From patchwork Tue Mar 2 14:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12113847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CAD3C433E0 for ; Wed, 3 Mar 2021 16:32:23 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BDAA64ED0 for ; Wed, 3 Mar 2021 16:32:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BDAA64ED0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:References:Mime-Version: Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=p7F2wdMGF53/6hN6nN311Ti6Ikjqtb8hTjV4TRQButU=; b=RT3pDd6ivPktm4 SAyNQbyjGftwP3JWdzq9UGBssnQp+TEfKuAOs1QCp85SfZJbSDTyd26ynNIcDErhbya643R4GOVnO iLOMdS7EUFbLHN36A57olAlw4jieEnId8BxDFXpyfi0cBt5TicXsw0VItiaOmCPlKOftIyb76YBJZ HQeNg0kxwWmWN4HLpMydsES3FwxV6HNot/0ppsljHU+pQZbln9sdY7jnTaFMg2pZf7w9OeKWya7x+ 2yOjTCvlEgeQjOzOM60+G8enx1FGCfLXeuJNWZBkIFk5lTAgAYqlp7V4bW05yTTVqiTX7pAfhIyN/ fCZNq4q2FvBlB9laQe4A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHUO0-005bpU-Jj; Wed, 03 Mar 2021 16:30:09 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSpm-005E2Y-SQ for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:50:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MUiu5cL4XJy7bcbjb67w8AVccQ6swyc7cTqk7H/pito=; b=Sey22SUnQTuQjYACNqdlwG0guQ Hvh1+zq7C/4kbNCXUdf1nc52nimkk0MFFNkMtbpw8dkyKxDb+683YFQNeUvm/WFjn27PfoZheDaRN XPd6iU+aPeUFhm3gvRu1MWy6Uo50mCwzkrmPEoYVFydwqofiz/E7pEbyrvKrNoM6d7lLzZ3hyBFkT ORNjYti9lifMcegGhosO4/+T+EyV8AVSFtldlmu/vlZAc765iwPPjdviUNazyKJyZniTImYZscQar BKY7Ys6wavy2piYTeTf/H0MhfCHykkfcAHTbNSyLECjYiffQ68rhb3sHrpbHJM6C0hYdqyLlfzfRS jJ+kemXQ==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6XZ-00HJNF-0I for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:02:28 +0000 Received: by mail-wm1-x349.google.com with SMTP id b62so1313427wmc.5 for ; Tue, 02 Mar 2021 07:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=MUiu5cL4XJy7bcbjb67w8AVccQ6swyc7cTqk7H/pito=; b=V2tQz8JIPctM0p8zJgSN56SE2f+sjG4GB6ZR55LMQiswnxYtR/ePVhbwO/o8W66G0b PbHVynwDMo4m5hQTkVbwHPUN6c0PkFKQE/sf5DH5nMyM0tggxmbD3FPQjbi6a0POeCz+ jh+2Nsxcsol/OZxoAVv6MqFZjCqNUXiv4O8MXjSVu9i+FDKGBgulOa9tkVjyrYK5Z9Bd Nq67f+OAletST31RgOjWXRR0vHMxg7CzWFcXeOoLWmi9Q4vWw9Jmfj0fTHu7FSTjC0o5 F2L8XjgbG6jShJL/W0Af7NMKKMKboklNsvT6OliD+fo6afqsvX1EexCiNHhJOW3b0KIF 4qmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MUiu5cL4XJy7bcbjb67w8AVccQ6swyc7cTqk7H/pito=; b=pER5O5UpDBWt2sDGgDe4+rtBqodbnynBhyDBgel6qXxtYIw/78kYWsofYz62RY4tri avXQGlrjPEqIE4eTDc4yIjGiRLf11Tr/3unJdlraeqZGmTHCqtk9gl3mpxwlnL9gALuZ kpi2DNqZva3Gy6HwtQK+KK71IbbFFmw2d6feyLiN3GjucEgTXyUpJ47BHoHEB3SSqoDS EnAV4Ij94AwA/6PDnarnJy4tzvYOQ9edVFbD+Hmn61Znjp3fAsIvf7+DhslUUWAao3+O NUMdiBBEl1H4YR6IaQD6DqSpuY2GATlFf7sQ9Rk+GmeKJFECz6lZO4+DXahfjgtfNfJZ MSYQ== X-Gm-Message-State: AOAM533cPd9pbrUY1OH396fy4fCJTD7fz3a3SBBPSo2sUkvsuZL8kYj1 4JuQ2BBWn5leuFYvMmz+CB08hbC+/LwX X-Google-Smtp-Source: ABdhPJz9F9KFBBfsTkBPKASwdRvs8WkwjMfKCJcm0vk7lvPEyGjjf4UWYBSGhgGbD6PbV21B/moA66tRIrG2 X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a7b:c18e:: with SMTP id y14mr495903wmi.1.1614697267665; Tue, 02 Mar 2021 07:01:07 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:57 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-28-qperret@google.com> Mime-Version: 1.0 References: <20210302150002.3685113-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 27/32] KVM: arm64: Refactor stage2_map_set_prot_attr() From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, qperret@google.com, robh+dt@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_150228_265724_7E3FB892 X-CRM114-Status: GOOD ( 11.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In order to ease its re-use in other code paths, refactor stage2_map_set_prot_attr() to not depend on a stage2_map_data struct. No functional change intended. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/pgtable.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 8e7059fcfd40..8aa01a9e2603 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -494,8 +494,7 @@ u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift) return vtcr; } -static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot, - struct stage2_map_data *data) +static kvm_pte_t stage2_get_prot_attr(enum kvm_pgtable_prot prot) { bool device = prot & KVM_PGTABLE_PROT_DEVICE; kvm_pte_t attr = device ? PAGE_S2_MEMATTR(DEVICE_nGnRE) : @@ -504,15 +503,15 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot, if (prot & KVM_PGTABLE_PROT_NONE) { if (prot != KVM_PGTABLE_PROT_NONE) - return -EINVAL; + return 0; attr |= KVM_PTE_LEAF_SW_BIT_PROT_NONE; - goto out; + return attr; } if (!(prot & KVM_PGTABLE_PROT_X)) attr |= KVM_PTE_LEAF_ATTR_HI_S2_XN; else if (device) - return -EINVAL; + return 0; if (prot & KVM_PGTABLE_PROT_R) attr |= KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R; @@ -523,9 +522,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot, attr |= FIELD_PREP(KVM_PTE_LEAF_ATTR_LO_S2_SH, sh); attr |= KVM_PTE_LEAF_ATTR_LO_S2_AF; -out: - data->attr = attr; - return 0; + return attr; } static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level, @@ -708,9 +705,9 @@ int kvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, .arg = &map_data, }; - ret = stage2_map_set_prot_attr(prot, &map_data); - if (ret) - return ret; + map_data.attr = stage2_get_prot_attr(prot); + if (!map_data.attr) + return -EINVAL; ret = kvm_pgtable_walk(pgt, addr, size, &walker); dsb(ishst);