@@ -2112,6 +2112,11 @@ int rshim_notify(rshim_backend_t *bd, int event, int code)
21122112static int rshim_find_index (char * dev_name )
21132113{
21142114 int i ;
2115+ bool pcie_device = false;
2116+ int compare_len ;
2117+
2118+ if (strncmp (dev_name , "pcie" , 4 ) == 0 )
2119+ pcie_device = true;
21152120
21162121 /* Need to match static device name if configured. */
21172122 if (rshim_static_dev_name && strcmp (rshim_static_dev_name , dev_name ))
@@ -2123,9 +2128,28 @@ static int rshim_find_index(char *dev_name)
21232128
21242129 /* First look for a match with a previous device name. */
21252130 for (i = 0 ; i < RSHIM_MAX_DEV ; i ++ ) {
2126- if (rshim_dev_names [i ] && !strcmp (dev_name , rshim_dev_names [i ])) {
2127- RSHIM_DBG ("Found match with previous at index %d\n" , i );
2128- return i ;
2131+ if (rshim_dev_names [i ]) {
2132+
2133+ /* Ignore the "function" part for PCIe BPF string, so for a rshim.conf
2134+ * string like "rshim1 pcie-0000:04:00.2", we will skip the ".2" part,
2135+ * thus if the user uses a simple string like "pcie-0000:04:00" or
2136+ * "pcie-0000:04:00.X", it will still match the device name to be
2137+ * compared.
2138+ */
2139+ if (pcie_device ) {
2140+ compare_len = strlen (dev_name ) - 2 ;
2141+ } else {
2142+ compare_len = strlen (dev_name );
2143+ }
2144+
2145+ if (!strncmp (dev_name , rshim_dev_names [i ], compare_len )) {
2146+ RSHIM_INFO ("Found match with previous at index %d\n" , i );
2147+ RSHIM_INFO ("dev_name: %s, rshim_dev_names[%d]: %s\n" ,
2148+ dev_name , i , rshim_dev_names [i ]);
2149+ // must replace simple string with full name
2150+ strcpy (rshim_dev_names [i ], dev_name );
2151+ return i ;
2152+ }
21292153 }
21302154 }
21312155
@@ -2789,13 +2813,30 @@ void rshim_deref(rshim_backend_t *bd)
27892813bool rshim_allow_device (const char * devname )
27902814{
27912815 int i ;
2816+ bool pcie_device = false;
2817+ int compare_len ;
2818+
2819+ if (strncmp (devname , "pcie" , 4 ) == 0 )
2820+ pcie_device = true;
27922821
27932822 if (rshim_static_dev_name && strcmp (rshim_static_dev_name , devname ))
27942823 return false;
27952824
2825+ /* Ignore the "function" part for PCIe BPF string, so for a rshim.conf
2826+ * string like "rshim1 pcie-0000:04:00.2", we will skip the ".2" part,
2827+ * thus even if the user specifies "pcie-0000:04:00" or
2828+ * "pcie-0000:04:00.X", it will still match the device name to be
2829+ * compared.
2830+ */
2831+ if (pcie_device ) {
2832+ compare_len = strlen (devname ) - 2 ;
2833+ } else {
2834+ compare_len = strlen (devname );
2835+ }
2836+
27962837 for (i = 0 ; i < RSHIM_MAX_DEV ; i ++ ) {
27972838 if (rshim_blocked_dev_names [i ] &&
2798- !strcmp (rshim_blocked_dev_names [i ], devname ))
2839+ !strncmp (rshim_blocked_dev_names [i ], devname , compare_len ))
27992840 return false;
28002841 }
28012842
0 commit comments