From owner-dev-commits-src-all@freebsd.org Mon Sep 27 19:15:11 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 791F066E09D; Mon, 27 Sep 2021 19:15:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HJC5C2yhcz4Zpg; Mon, 27 Sep 2021 19:15:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4549C1656C; Mon, 27 Sep 2021 19:15:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18RJFBm2002308; Mon, 27 Sep 2021 19:15:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18RJFBUp002307; Mon, 27 Sep 2021 19:15:11 GMT (envelope-from git) Date: Mon, 27 Sep 2021 19:15:11 GMT Message-Id: <202109271915.18RJFBUp002307@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: David Bright Subject: git: e3cf7ebc1d36 - main - ntb_hw_intel: fix xeon NTB gen3 bar disable logic MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dab X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e3cf7ebc1d36d068f1d1a83ea73ce2eed547e3cb Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2021 19:15:11 -0000 The branch main has been updated by dab: URL: https://cgit.FreeBSD.org/src/commit/?id=e3cf7ebc1d36d068f1d1a83ea73ce2eed547e3cb commit e3cf7ebc1d36d068f1d1a83ea73ce2eed547e3cb Author: David Bright AuthorDate: 2021-09-27 13:18:46 +0000 Commit: David Bright CommitDate: 2021-09-27 19:13:03 +0000 ntb_hw_intel: fix xeon NTB gen3 bar disable logic In NTB gen3 driver, it was supposed to disable NTB bar access by default, but due to incorrect register access method, the bar disable logic does not work as expected. Those registers should be modified through NTB bar0 rather than PCI configuration space. Besides, we'd better to protect ourselves from a bad buddy node so ingress disable logic should be implemented together. Submitted by: Austin Zhang (austin.zhang@dell.com) Reviewers: markj, mav, vangyzen, dab Differential Revision: https://reviews.freebsd.org/D31736 Sponsored by: Dell EMC MFC to: stable/12, stable/13 MFC after: 1 week --- sys/dev/ntb/ntb_hw/ntb_hw_intel.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/sys/dev/ntb/ntb_hw/ntb_hw_intel.c b/sys/dev/ntb/ntb_hw/ntb_hw_intel.c index 06206f812d3f..00fcc4829b9c 100644 --- a/sys/dev/ntb/ntb_hw/ntb_hw_intel.c +++ b/sys/dev/ntb/ntb_hw/ntb_hw_intel.c @@ -2163,15 +2163,21 @@ xeon_gen3_setup_b2b_mw(struct ntb_softc *ntb) intel_ntb_reg_write(8, XEON_GEN3_REG_IMBAR2XBASE, 0); /* - * If the value in EMBAR1LIMIT is set equal to the value in EMBAR1, - * the memory window for EMBAR1 is disabled. - * Note: It is needed to avoid malacious access. + * If the value in IMBAR1XLIMIT is set equal to the value in IMBAR1XBASE, + * the local memory window exposure from EMBAR1 is disabled. + * Note: It is needed to avoid malicious access. */ - reg = pci_read_config(ntb->device, XEON_GEN3_EXT_REG_BAR1BASE, 8); - intel_ntb_reg_write(8, XEON_GEN3_REG_IMBAR1XLIMIT, reg); + intel_ntb_reg_write(8, XEON_GEN3_REG_IMBAR1XLIMIT, 0); + intel_ntb_reg_write(8, XEON_GEN3_REG_IMBAR2XLIMIT, 0); - reg = pci_read_config(ntb->device, XEON_GEN3_EXT_REG_BAR2BASE, 8); - intel_ntb_reg_write(8, XEON_GEN3_REG_IMBAR2XLIMIT, reg); + /* Config outgoing translation limits (whole bar size windows) */ + reg = intel_ntb_reg_read(8, XEON_GEN3_REG_EMBAR1XBASE); + reg += ntb->bar_info[NTB_B2B_BAR_1].size; + intel_ntb_reg_write(8, XEON_GEN3_REG_EMBAR1XLIMIT, reg); + + reg = intel_ntb_reg_read(8, XEON_GEN3_REG_EMBAR2XBASE); + reg += ntb->bar_info[NTB_B2B_BAR_2].size; + intel_ntb_reg_write(8, XEON_GEN3_REG_EMBAR2XLIMIT, reg); return (0); } @@ -3226,7 +3232,10 @@ intel_ntb_mw_set_trans(device_t dev, unsigned idx, bus_addr_t addr, size_t size) limit = 0; if (bar_is_64bit(ntb, bar_num)) { - base = intel_ntb_reg_read(8, base_reg) & BAR_HIGH_MASK; + if (ntb->type == NTB_XEON_GEN3) + base = addr; + else + base = intel_ntb_reg_read(8, base_reg) & BAR_HIGH_MASK; if (limit_reg != 0 && size != mw_size) limit = base + size; @@ -3249,18 +3258,6 @@ intel_ntb_mw_set_trans(device_t dev, unsigned idx, bus_addr_t addr, size_t size) intel_ntb_reg_write(8, xlat_reg, 0); return (EIO); } - - if (ntb->type == NTB_XEON_GEN3) { - limit = base + size; - - /* set EMBAR1/2XLIMIT */ - if (!idx) - intel_ntb_reg_write(8, - XEON_GEN3_REG_EMBAR1XLIMIT, limit); - else - intel_ntb_reg_write(8, - XEON_GEN3_REG_EMBAR2XLIMIT, limit); - } } else { /* Configure 32-bit (split) BAR MW */ if (ntb->type == NTB_XEON_GEN3)