From patchwork Mon Nov 6 08:50:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 834515 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVmlY6m8Yz9s83 for ; Mon, 6 Nov 2017 20:02:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jzHk1bG2"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yVmlY4ZHzzDr5S for ; Mon, 6 Nov 2017 20:02:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jzHk1bG2"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::241; helo=mail-qt0-x241.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jzHk1bG2"; dkim-atps=neutral Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yVmbz4dRlzDr5J for ; Mon, 6 Nov 2017 19:55:27 +1100 (AEDT) Received: by mail-qt0-x241.google.com with SMTP id z19so9959238qtg.11 for ; Mon, 06 Nov 2017 00:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=76v0uaQ/yP7c+a92nkjUmP82ox8KaaCxEzA/Xai6+fI=; b=jzHk1bG2MvMPj//7WA+b+FdKGNVjiENO+vF3TPDCktnR2r/gY0lt0OBNbYAPInXQCv uXQidllaVNj/HpGsTvoFGhnqUyBtQDB5xWYMaPSt3X7KEUOncQcOBfvSqhNtRhMHs1nL IGnV5sLgFYDZwsw5eMMQA934ujHI2iH3fk+KJCXjZ0K5ihhTFGDUIFmsS0pUKQjGLb9t Ss1VLfPcETuAf3nRf+u3kfcZPOk4LmLoNNBuAXVuUwMuM5/2nF29SA4WltNNqRGhXNKT 5OeWkKVVle0EIOL8LWpvPQEGdE0r0t/rHwi5Zem9vuE82egBu1n+f1+PcN3GY60rx+P3 GllA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=76v0uaQ/yP7c+a92nkjUmP82ox8KaaCxEzA/Xai6+fI=; b=PoH/ARPsLQbJNzx4WtgYmq3PyfQYAE+g5fJNc1S1v1/QaEcG3Fiwib5JqdTuCjW5NP sq692vZO9JCh7gB2MBx/bsx9b2ubn0ULG9Nqke9rSEQshcAC+eGaUvj04gwXVQ/+A2bu yPDp3sNS0UHGuSnTGToq86eLBGmD1XV/jz5AhkYpUkaCBJFnoyTlOxwytSfr+1M/BeLm kPKVPH2NP8Jlf2TtZFPIKTWzg3lz3PHdFF8yvFL8yvgQFtjPc4ooCNkvXrCJloD5D3Qh 3+Tz+9+Bt8qW7kC91jdJ+vBcniTA0zrC/xgL2rq7FO0GqfWBiHeJdPxCGcc4sRG22Mwx Okkw== X-Gm-Message-State: AJaThX7Ue6ufQv69qCzpmwrQ/xs+ZT+ryFF7Z5uXubVxftZWYmEHlssr cm1xSx2j/hDarhfVZjrfIys= X-Google-Smtp-Source: ABhQp+SRvDQKjy+7fk3YZn/U5zK5AKQq4b9mCkJWNSzn37ztTcrjwZ6vCmqj5u4PYPgDASdMYMnMlA== X-Received: by 10.237.55.200 with SMTP id j66mr21489129qtb.210.1509958524344; Mon, 06 Nov 2017 00:55:24 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id x80sm2471528qkx.33.2017.11.06.00.55.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:55:23 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au Subject: [PATCH v9 1/8] powerpc: introduce pte_set_hidx() helper Date: Mon, 6 Nov 2017 00:50:45 -0800 Message-Id: <1509958252-18302-2-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958252-18302-1-git-send-email-linuxram@us.ibm.com> References: <1509958252-18302-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ebiederm@xmission.com, linuxram@us.ibm.com, mhocko@kernel.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Introduce pte_set_hidx().It sets the (H_PAGE_F_SECOND|H_PAGE_F_GIX) bits at the appropriate location in the PTE of 4K PTE. For 64K PTE, it sets the bits in the second part of the PTE. Though the implementation for the former just needs the slot parameter, it does take some additional parameters to keep the prototype consistent. This function will be handy as we work towards re-arranging the bits in the subsequent patches. Acked-by: Balbir Singh Reviewed-by: Aneesh Kumar K.V Signed-off-by: Ram Pai --- arch/powerpc/include/asm/book3s/64/hash-4k.h | 14 ++++++++++++++ arch/powerpc/include/asm/book3s/64/hash-64k.h | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/include/asm/book3s/64/hash-4k.h index 197ced1..2975fc1 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-4k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h @@ -49,6 +49,20 @@ static inline int hash__hugepd_ok(hugepd_t hpd) } #endif +/* + * 4K PTE format is different from 64K PTE format. Saving the hash_slot is just + * a matter of returning the PTE bits that need to be modified. On 64K PTE, + * things are a little more involved and hence needs many more parameters to + * accomplish the same. However we want to abstract this out from the caller by + * keeping the prototype consistent across the two formats. + */ +static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte, + unsigned int subpg_index, unsigned long hidx) +{ + return (hidx << H_PAGE_F_GIX_SHIFT) & + (H_PAGE_F_SECOND | H_PAGE_F_GIX); +} + #ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline char *get_hpte_slot_array(pmd_t *pmdp) diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/include/asm/book3s/64/hash-64k.h index 8d40cf0..c1bd258 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-64k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h @@ -68,6 +68,8 @@ static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep) return rpte; } +#define HIDX_BITS(x, index) (x << (index << 2)) + static inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index) { if ((pte_val(rpte.pte) & H_PAGE_COMBO)) @@ -75,6 +77,29 @@ static inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index) return (pte_val(rpte.pte) >> H_PAGE_F_GIX_SHIFT) & 0xf; } +/* + * Commit the hidx and return PTE bits that needs to be modified. The caller is + * expected to modify the PTE bits accordingly and commit the PTE to memory. + */ +static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte, + unsigned int subpg_index, unsigned long hidx) +{ + unsigned long *hidxp = (unsigned long *)(ptep + PTRS_PER_PTE); + + rpte.hidx &= ~HIDX_BITS(0xfUL, subpg_index); + *hidxp = rpte.hidx | HIDX_BITS(hidx, subpg_index); + + /* + * Anyone reading PTE must ensure hidx bits are read after reading the + * PTE by using the read-side barrier smp_rmb(). __real_pte() can be + * used for that. + */ + smp_wmb(); + + /* No PTE bits to be modified, return 0x0UL */ + return 0x0UL; +} + #define __rpte_to_pte(r) ((r).pte) extern bool __rpte_sub_valid(real_pte_t rpte, unsigned long index); /*