Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4679831pxj; Wed, 12 May 2021 10:43:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoQnobQHVtHquBa/4A1D7XSQV8bwB9WAp9EKIFPMBkZeGOcRZlBYfTQWztZhpnVXWh0yt3 X-Received: by 2002:a50:8fe6:: with SMTP id y93mr44566056edy.224.1620841406528; Wed, 12 May 2021 10:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620841406; cv=none; d=google.com; s=arc-20160816; b=CzmPlaxJuZ7wRML/iKWBQgwbZEXHGO/ZK3VVlFUTq5N5dNlXewkyKqevraMX95YgB5 tMa0N4t4X1M3reOC4FYuwy8qxbSAnUp6r7j9xhfM3q3mKlX91MjHxMi55hY6WMgV65cL pQjPRT5MInP5R0koi4Y9AARX/hXcEPJs27mNC06hJmRW7R0Wk6VV5ixcoHOpk0XruF+1 QG95HdTZ90E7zQowo2hr0DIxyAVTFg/xjAKtjlY89pNXUcSrGnomY93FzteMGi+D+R6H D2oBVa5aLLGe3sSKw6Cw/nwoV7LKQx87L9hafz6W2daYZxGcKJyFWQd4ixLbdMr0q9K/ Y/tw== 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=zOC/kTKMo986w4/YcWd8q9kRVM0kW+8H01SmbGvnYJyra7dbHWC9KZzfIvigGphwaV NtI3k65mjyKx8K/Czs/wuBcdkZvmHFxmt5+3cTox3hP6h77WkE7NNC3KBnsM+225KSv/ baesgOiK+P1ntJlt670xJQ6PNCXQ1OdeQmOBqGeoNOnARct0WIZX6I3q7E3/6tnsC3VG Bwg87VX16bCjCw5sFHsmF5aytMe311nybvrHbHwUmuVYCuIq+AS97noETCFeajW+s1CP Xr9dfgg5Fh67XLEoR3lb+piIk18OwLZaoP2PyLKeUpZf18cr854aFfv6HZl4pTye87b8 MZbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=chUDXAK8; 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 b21si270958edw.501.2021.05.12.10.43.03; Wed, 12 May 2021 10:43:26 -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=chUDXAK8; 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 S234983AbhELRnG (ORCPT + 99 others); Wed, 12 May 2021 13:43:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:58402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240200AbhELQRd (ORCPT ); Wed, 12 May 2021 12:17:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 311E061D6B; Wed, 12 May 2021 15:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834209; bh=l53qjLtTzEQnkdS0F5TN+5MEX+fHKQbbD5Dpr9JVCBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chUDXAK88OZkSgtiMP+uf83LTdVeAHFBNRc6H+y1Wxmg3KkGZyxakcJJ8vdz66fMu cCKClU0VVgFOcgNIfYPR0P3ttz4mRHjYji6ArmnWSWf6ME8hlcIoQs4hcMf4hryhjq KuS95h3GZzQJUcyGJDV+UPZTTNyF2VJxJt4Gz1m4= 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.11 453/601] powerpc/pseries: Add key to flags in pSeries_lpar_hpte_updateboltedpp() Date: Wed, 12 May 2021 16:48:50 +0200 Message-Id: <20210512144842.762081287@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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