Your GeForce runs AI at half speed. This fixes it for 20/30/40 series cards. Up to 2× FP16 / BF16 / TF32 tensor throughput
C
Claim cards on older kernels and behind BME-setting firmware
Khoa Truongd04f5a00f30d
diff --git a/README.md b/README.mdindex 33278ca..6d4edac 100644--- a/README.md+++ b/README.md@@ -70,9 +70,11 @@ Addresses are full PCI names as `lspci -D` prints them (hex digits in eithercase), independent of GPU numbering and display role. An entry that is nota GA102/GA104 card, including `all` mixed with addresses, is logged and ignored.The cards are unlocked concurrently, about a second in all however many-there are, and each on its own: a card that is already bound, powered down-or bus mastering is skipped. Then `nvidia` loads and binds every card as-usual.+there are, and each on its own: a card that is already bound or powered+down is skipped. Bus mastering that the board firmware left on (Supermicro+X11 does this whatever its option ROM and bus master settings) is cleared+first; a card some driver already initialised is still refused. Then+`nvidia` loads and binds every card as usual.The display card works too. Its firmware framebuffer (the boot console andPlymouth) keeps running while the unlock's firmware steps run, and isdiff --git a/kernel/gpu_unlock/unlock_610.c b/kernel/gpu_unlock/unlock_610.cindex 82a3396..5a93a8a 100644--- a/kernel/gpu_unlock/unlock_610.c+++ b/kernel/gpu_unlock/unlock_610.c@@ -798,7 +798,10 @@ static int unlock_transaction_claim(struct unlock_transaction_work *work)dev_info(&work->pdev->dev, "claim: power=%d pm_cap=%#x flags=%#x\n",work->pdev->current_state, work->pdev->pm_cap, work->pdev->dev_flags);- if (work->pdev->current_state != PCI_D0 ||+ /* Older kernels (seen on 6.8 and 6.14) leave a device no driver has+ * enabled at PCI_UNKNOWN. Accept that only when PMCSR confirms D0. */+ if ((work->pdev->current_state != PCI_D0 &&+ (work->pdev->current_state != PCI_UNKNOWN || !work->pdev->pm_cap)) ||(work->pdev->pm_cap &&(diag_pci_word(work, false, work->pdev->pm_cap + PCI_PM_CTRL, &pmcsr) ||(pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0)))@@ -812,8 +815,18 @@ static int unlock_transaction_claim(struct unlock_transaction_work *work)return GU_RESULT(-ENODEV);work->original_cmd = command;work->cmd_valid = true;- if (command & PCI_COMMAND_MASTER)- return GU_RESULT(-EBUSY);+ /* Some firmware (Supermicro X11 AMI) hands every card over with BME set,+ * whatever its option ROM and bus master settings. No driver is bound,+ * and the WPR2 check still refuses a card that one has initialised. */+ if (command & PCI_COMMAND_MASTER) {+ command &= ~PCI_COMMAND_MASTER;+ if (pci_write_config_word(work->pdev, PCI_COMMAND, command) ||+ diag_pci_word(work, false, PCI_COMMAND, &command) ||+ command == 0xffff || (command & PCI_COMMAND_MASTER))+ return GU_RESULT(-EBUSY);+ dev_info(&work->pdev->dev, "claim: cleared firmware BME\n");+ work->original_cmd = command;+ }dev_info(&work->pdev->dev, "claim: command=%#x capability=%#x BAR_mask=%#x\n",command, cap, pci_select_bars(work->pdev, IORESOURCE_MEM));/* Only BAR0 is mapped. On the display card the firmware framebuffer keepsdiff --git a/tests/test_unlock_adapter.c b/tests/test_unlock_adapter.cindex bc9e55b..1b5d32d 100644--- a/tests/test_unlock_adapter.c+++ b/tests/test_unlock_adapter.c@@ -15,7 +15,7 @@ static struct {u16 cmd,saved;unsigned long now;int allocs,live,frees,fail_alloc,fail_mask,flrs,fail_reset,starts,boot_mode,bar_bad,barriers,writes;- int gsp_starts,fwsec_mode,master_fail,selector_writes,ss1_writes,fw_live;+ int gsp_starts,fwsec_mode,master_fail,master_stuck,selector_writes,ss1_writes,fw_live;int pending,lost_identity,corrupt_selector,alien_wpr;int fw_requests,fail_fw,fail_claim,fail_map,fail_save,fail_context,pins,selector_bad;int restore_mask_fail,late_devres;@@ -165,7 +165,7 @@ int pci_read_config_word(struct pci_dev *p,int r,u16 *v) {*v=r==PCI_COMMAND?fakeint pci_read_config_dword(struct pci_dev *p,int r,u32 *v) {*v=r==PCI_VENDOR_ID?(fake.flrs && fake.lost_identity?~0u:0x220410de):(u32)fake.bar_bad;return 0;}-int pci_write_config_word(struct pci_dev *p,int r,u16 v) {assert(r==PCI_COMMAND);fake.cmd=v;return 0;}+int pci_write_config_word(struct pci_dev *p,int r,u16 v) {assert(r==PCI_COMMAND);fake.cmd=v|(fake.master_stuck?4:0);return 0;}int pcie_capability_read_word(struct pci_dev *p,int r,u16 *v) {*v=r==PCI_EXP_DEVSTA?fake.pending:0;return 0;}int pcie_capability_read_dword(struct pci_dev *p,int r,u32 *v) {*v=PCI_EXP_DEVCAP_FLR;return 0;}int pci_is_pcie(struct pci_dev *p) {return 1;}@@ -544,7 +544,8 @@ int main(int argc, char **argv) {"wpr-disabled-zero","wpr-inverted","wpr-inaccessible","post-gfw-late","post-gfw-timeout","post-gfw-inaccessible","post-gsp-resumed","wpr-frts-retained","firmware-group-oom-first","firmware-group-oom-later","devres-preexisting","devres-at-handoff",- "warm-wpr2","ss1-readback","ss1-lost"};+ "warm-wpr2","ss1-readback","ss1-lost","power-unknown","power-unknown-no-pm",+ "firmware-bme","firmware-bme-stuck"};int total_allocations=0;for(unsigned scenario=0;scenario<ARRAY_SIZE(cases);scenario++) {setup(&w);@@ -606,12 +607,17 @@ int main(int argc, char **argv) {if(scenario==55)regs[0x1fa828/4]=fake.fwsec_wpr_hi; /* a driver already ran FWSEC */if(scenario==56)fake.selector_bad=2;if(scenario==57)fake.corrupt_selector=2;+ if(scenario==58 || scenario==59)dev.current_state=PCI_UNKNOWN;+ if(scenario==58)dev.pm_cap=0x60;+ if(scenario==60 || scenario==61)fake.cmd=6; /* firmware left BME set */+ if(scenario==61)fake.master_stuck=1;/* As main.c: the GSP file is loaded once, ahead of every card. */struct gpu_unlock_610_shared shared={0};last_work=NULL;int ret=gpu_unlock_610_load_shared(&dev,&shared);if(!ret)ret=gpu_unlock_610_unlock(&dev,&shared);gpu_unlock_610_release_shared(&shared);- bool expected=scenario<2 || (scenario>=33 && scenario<=35) || scenario==39 || scenario==40 || scenario==43 || scenario==46;+ bool expected=scenario<2 || (scenario>=33 && scenario<=35) || scenario==39 || scenario==40 || scenario==43 || scenario==46 ||+ scenario==58 || scenario==60;bool retained=fake.pins;if((!ret)!=expected)fprintf(stderr,"%s\n%s: error=%d\n",fake.log,cases[scenario],ret);assert((!ret)==expected);@@ -648,7 +654,8 @@ int main(int argc, char **argv) {assert(!unlock_transaction_unwind(last_work));pci_dev_put(last_work->pdev);free(last_work);}- assert(!fake.live && !fake.fw_live && dev.refs==1 && !(fake.cmd&4));+ /* A card whose BME will not clear is left as found. */+ assert(!fake.live && !fake.fw_live && dev.refs==1 && (scenario==61 || !(fake.cmd&4)));assert(!fake.group_live && fake.cache_records==fake.cache_released);assert(dev.dev.devres_head.count==(scenario==53 || scenario==54?1u:0u));if(scenario>=51 && scenario<=53)assert(!fake.writes && !fake.allocs && !fake.flrs);@@ -659,6 +666,9 @@ int main(int argc, char **argv) {if(scenario==33)assert(fake.cmd==0);if(scenario==56)assert(ret==-EIO && retained && fake.ss1_writes==1 && !fake.flrs);if(scenario==57)assert(ret==-EIO && !retained && fake.flrs==1);+ if(scenario==59)assert(ret==-EOPNOTSUPP && !fake.allocs && !fake.flrs);+ if(scenario==60)assert(strstr(fake.log,"claim: cleared firmware BME"));+ if(scenario==61)assert(ret==-EBUSY && !fake.allocs && !fake.flrs);if(scenario==55) {assert(ret==-EBUSY && !retained && !fake.gsp_starts && !fake.starts && !fake.flrs);assert(strstr(fake.log,"card already initialised since power on"));diff --git a/tests/unlock_shim/compat.h b/tests/unlock_shim/compat.hindex 9d930de..2e575f4 100644--- a/tests/unlock_shim/compat.h+++ b/tests/unlock_shim/compat.h@@ -29,6 +29,7 @@ void test_device_log(const char *, ...) __attribute__((format(printf, 1, 2)));#define dev_err(dev, ...) test_device_log(__VA_ARGS__)#define dev_info(dev, ...) test_device_log(__VA_ARGS__)#define PCI_D0 0+#define PCI_UNKNOWN 5#define PCI_DEV_FLAGS_NO_FLR_RESET (1u << 10)#define PCI_VENDOR_ID 0#define PCI_COMMAND 4