Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4744058pxj; Wed, 12 May 2021 12:12:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsvghbTL2JKz1pSQ+Vf7nCPiK4kCjEAGt+841cKsiex7FBzH2bJDHUG0POOTHIjqx/9mI3 X-Received: by 2002:a05:6402:515:: with SMTP id m21mr45422506edv.117.1620846764577; Wed, 12 May 2021 12:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620846764; cv=none; d=google.com; s=arc-20160816; b=AH9aFgpmRa+c6GIZHxEAOjCXHwuJwTpdktrwq6lIsgtc2Zf5LsDv9J+yTRdMXO7MGb FLW3qFrb4itlJ/kCz1a8qn+7Hk9o0VN9OuAQrN1e3b7oKL3QbkkwYoaqS4UI2uPZ97S5 GgZItrO9Mo83YpSUAgE8x1oiP9KFziGgonRhPo35uBtd208+xhklJnaV/pTtQWqP6Uqh Yp6NQ9vNxTt+ncoDZXGlz4BLIg7JHEU4TqitMzcbWY8SFstkdzMt9CPTANUSJ54bua8b Xg6d/ancjwEov8SRkJ2dC7f15eLv7AtR2utaJZCN6vwg4CNurVQLHLhJc0IWvqml5p21 R3Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fWZTiEMM5LkXbWkzfFAqf4ymdiWo7FAISxQE6wewZ9Y=; b=tKke4QNyAccnqF6d+v9gcANz8b6D1Zg1Harf2aU+C7PH6sMGitqhy75QqaaViMmi7d tFhsRBI1oxaKLNDgpUsv7MaghCjnNoX/b3LcoXhrZTrjZrx+valvmetlN/3UHvUb7GsC M4LVKdu+S4/HDy6CmC4MfAJ3cv3bFmFFiXVVvUWQUU7D9KTub5Fyp4WJTbP5WhJijcmY pTx8JO3SumX796AUDaKqDomWqaWkhu5gSBYrR38sM2hex64Xe9Eilqglwk+vR54QO34K e+OzXZ2p2rK+F+hSX3VhVIHbgeqtmeVLbmCOe7RgoLqc6u7piGrb5CMD5iTAuyHwlkmp x2Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="FsSo/cr5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e23si674499ejh.183.2021.05.12.12.12.20; Wed, 12 May 2021 12:12:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="FsSo/cr5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377100AbhELTCe (ORCPT + 99 others); Wed, 12 May 2021 15:02:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:35834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244104AbhELQmf (ORCPT ); Wed, 12 May 2021 12:42:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3B0D561D31; Wed, 12 May 2021 16:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835844; bh=l53qjLtTzEQnkdS0F5TN+5MEX+fHKQbbD5Dpr9JVCBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FsSo/cr5/4ZWrADmoYTou27P1qdhvdZzTUuFmtWuYb3+GHncxxsAM8Ep704Bm7jhh f+L0raYLkDVWds51IeBsLJGDBQBTj2HFKyE6ASsCqXIkFHFsRs1uylr2AXKMLTZc2D UzDN+DjS7V34XYbsDVZeb5CQnC3eMsdDdkK4RGAY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Sasha Levin Subject: [PATCH 5.12 507/677] powerpc/pseries: Add key to flags in pSeries_lpar_hpte_updateboltedpp() Date: Wed, 12 May 2021 16:49:13 +0200 Message-Id: <20210512144854.227562877@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Ellerman [ Upstream commit b56d55a5aa4aa9fc166595a7feb57f153ef7b555 ] The flags argument to plpar_pte_protect() (aka. H_PROTECT), includes the key in bits 9-13, but currently we always set those bits to zero. In the past that hasn't been a problem because we always used key 0 for the kernel, and updateboltedpp() is only used for kernel mappings. However since commit d94b827e89dc ("powerpc/book3s64/kuap: Use Key 3 for kernel mapping with hash translation") we are now inadvertently changing the key (to zero) when we call plpar_pte_protect(). That hasn't broken anything because updateboltedpp() is only used for STRICT_KERNEL_RWX, which is currently disabled on 64s due to other bugs. But we want to fix that, so first we need to pass the key correctly to plpar_pte_protect(). We can't pass our newpp value directly in, we have to convert it into the form expected by the hcall. The hcall we're using here is H_PROTECT, which is specified in section 14.5.4.1.6 of LoPAPR v1.1. It takes a `flags` parameter, and the description for flags says: * flags: AVPN, pp0, pp1, pp2, key0-key4, n, and for the CMO option: CMO Option flags as defined in Table 189‚ If you then go to the start of the parent section, 14.5.4.1, on page 405, it says: Register Linkage (For hcall() tokens 0x04 - 0x18) * On Call * R3 function call token * R4 flags (see Table 178‚ “Page Frame Table Access flags field definition‚” on page 401) Then you have to go to section 14.5.3, and on page 394 there is a list of hcalls and their tokens (table 176), and there you can see that H_PROTECT == 0x18. Finally you can look at table 178, on page 401, where it specifies the layout of the bits for the key: Bit Function ----------------- 50-54 | key0-key4 Those are big-endian bit numbers, converting to normal bit numbers you get bits 9-13, or 0x3e00. In the kernel we have: #define HPTE_R_KEY_HI ASM_CONST(0x3000000000000000) #define HPTE_R_KEY_LO ASM_CONST(0x0000000000000e00) So the LO bits of newpp are already in the right place, and the HI bits need to be shifted down by 48. Fixes: d94b827e89dc ("powerpc/book3s64/kuap: Use Key 3 for kernel mapping with hash translation") Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210331003845.216246-2-mpe@ellerman.id.au Signed-off-by: Sasha Levin --- arch/powerpc/platforms/pseries/lpar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c index 3805519a6469..cd38bd421f38 100644 --- a/arch/powerpc/platforms/pseries/lpar.c +++ b/arch/powerpc/platforms/pseries/lpar.c @@ -977,11 +977,13 @@ static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp, slot = pSeries_lpar_hpte_find(vpn, psize, ssize); BUG_ON(slot == -1); - flags = newpp & 7; + flags = newpp & (HPTE_R_PP | HPTE_R_N); if (mmu_has_feature(MMU_FTR_KERNEL_RO)) /* Move pp0 into bit 8 (IBM 55) */ flags |= (newpp & HPTE_R_PP0) >> 55; + flags |= ((newpp & HPTE_R_KEY_HI) >> 48) | (newpp & HPTE_R_KEY_LO); + lpar_rc = plpar_pte_protect(flags, slot, 0); BUG_ON(lpar_rc != H_SUCCESS); -- 2.30.2