From mboxrd@z Thu Jan 1 00:00:00 1970 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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 D114AC636C8 for ; Tue, 20 Jul 2021 10:23:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC3C2611C1 for ; Tue, 20 Jul 2021 10:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236909AbhGTJkx (ORCPT ); Tue, 20 Jul 2021 05:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236843AbhGTJjB (ORCPT ); Tue, 20 Jul 2021 05:39:01 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14F7AC0613DE for ; Tue, 20 Jul 2021 03:17:41 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id h24-20020a9d64180000b029036edcf8f9a6so21092670otl.3 for ; Tue, 20 Jul 2021 03:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3nSJt2wVIh6BPso+/5eEugChhl7K9J9KvL28I6hU2Mc=; b=GYmt8m/9xcpbfJpN+JDFmpyQSiDjQCb2/C4Arok72cqv+29SFuIJytkUrLba4/h+yJ S5kStZCpS/bjSyihG7MOnHe7cl6OnFiucpWXpykGdrB5sdipCaSB8Mr5r8RirOqjZZeX WfF7zxiBwr002UhhGIDgI6mfde7vtmlHyoxITYCgpo+UD9UFYM0WB12yJrweVBTL9JJt bEw/vodpV8o7GOxQZeTw4s2MTq7awvaU+7ls6ue7g6ggbra4UyhNdyVorfiugB4gZXt0 KDuYdgE0NQotaJA/LI0UIW72g3iiFByxEIuPoaA0jns92tBXCSepKXSLpZanvY6KzDIP fHeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3nSJt2wVIh6BPso+/5eEugChhl7K9J9KvL28I6hU2Mc=; b=ZoPjEBxeDcE77jriaxQCcaQyz4zffuK1inm5FqRwTz/OVz2bxVujoZRWAbh1db3/CQ 6gEFW/5ZeRGLJ9wj7DW7UhWBtz4BpZA3lI3L1RF5m7Wif45RdIJaKxq7HOgkXLSKfrOv O2AIbQcoMvNdU1+K7yTFXo74ndZ/rvyI4/UH8WHLxFQ8sZVaP/nQLLUB/Pvr3hbxrv2A u9m4/AKMZZ+HZlxl5j1G5eIeZ76aVMBUHTfYraSk5DYble7QzCgkW2QUvENPaSaAkECZ 7XXvKVDyDrdezM5GbJbd6/KJAiFVfFI0dDQSG4pAKoCqjcsImXz/b1Yp+rELrPUz+Ei2 poNA== X-Gm-Message-State: AOAM532zxPqCvLEEO38RLm5j2OKlbz3lYFQ/CL+QF3pDr17PuckgERCx x1KcIoLzkMoO5+2yD+LA/94DIyT3koJLv/x3cfo3VA== X-Google-Smtp-Source: ABdhPJwvdbge9dFU6ODLriZxUOU3MC1qOuSsWZfB9Ag10DwHavakZNHULRmsBxP5cWZD1feem6Z/2nFZ3dkKu0EzFlA= X-Received: by 2002:a9d:600a:: with SMTP id h10mr21242926otj.144.1626776260256; Tue, 20 Jul 2021 03:17:40 -0700 (PDT) MIME-Version: 1.0 References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-7-qperret@google.com> In-Reply-To: <20210719104735.3681732-7-qperret@google.com> From: Fuad Tabba Date: Tue, 20 Jul 2021 11:17:03 +0100 Message-ID: Subject: Re: [PATCH 06/14] KVM: arm64: Tolerate re-creating hyp mappings to set ignored bits To: Quentin Perret Cc: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, dbrazdil@google.com, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Quentin, On Mon, Jul 19, 2021 at 11:47 AM Quentin Perret wrote: > > The current hypervisor stage-1 mapping code doesn't allow changing an > existing valid mapping. Relax this condition by allowing changes that > only target ignored bits, as that will soon be needed to annotate shared > pages. > > Signed-off-by: Quentin Perret > --- > arch/arm64/kvm/hyp/pgtable.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index a0ac8c2bc174..34cf67997a82 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -362,6 +362,17 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > return 0; > } > > +static bool hyp_pte_needs_update(kvm_pte_t old, kvm_pte_t new) > +{ > + if (old == new) > + return false; > + > + if (!kvm_pte_valid(old)) > + return true; > + > + return !WARN_ON((old ^ new) & ~KVM_PTE_LEAF_ATTR_IGNORED); Wouldn't this return false if both ignored and non-ignored bits were different, or is that not possible (judging by the WARN_ON)? If it is, then it would need an update, wouldn't it? Thanks, /fuad > +} > + > static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > kvm_pte_t *ptep, struct hyp_map_data *data) > { > @@ -371,9 +382,12 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > if (!kvm_block_mapping_supported(addr, end, phys, level)) > return false; > > - /* Tolerate KVM recreating the exact same mapping */ > + /* > + * Tolerate KVM recreating the exact same mapping, or changing ignored > + * bits. > + */ > new = kvm_init_valid_leaf_pte(phys, data->attr, level); > - if (old != new && !WARN_ON(kvm_pte_valid(old))) > + if (hyp_pte_needs_update(old, new)) > smp_store_release(ptep, new); > > data->phys += granule; > -- > 2.32.0.402.g57bb445576-goog > From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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 4B94AC07E95 for ; Tue, 20 Jul 2021 10:17:45 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id B339F6113C for ; Tue, 20 Jul 2021 10:17:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B339F6113C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 337094A51D; Tue, 20 Jul 2021 06:17:44 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PI-3y-rgyK6L; Tue, 20 Jul 2021 06:17:43 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 32E604B0A3; Tue, 20 Jul 2021 06:17:43 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 1B9A84A51D for ; Tue, 20 Jul 2021 06:17:42 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H9Vf57XBEmlv for ; Tue, 20 Jul 2021 06:17:41 -0400 (EDT) Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 234D04A3A5 for ; Tue, 20 Jul 2021 06:17:41 -0400 (EDT) Received: by mail-ot1-f53.google.com with SMTP id b18-20020a0568303112b02904cf73f54f4bso7514693ots.2 for ; Tue, 20 Jul 2021 03:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3nSJt2wVIh6BPso+/5eEugChhl7K9J9KvL28I6hU2Mc=; b=GYmt8m/9xcpbfJpN+JDFmpyQSiDjQCb2/C4Arok72cqv+29SFuIJytkUrLba4/h+yJ S5kStZCpS/bjSyihG7MOnHe7cl6OnFiucpWXpykGdrB5sdipCaSB8Mr5r8RirOqjZZeX WfF7zxiBwr002UhhGIDgI6mfde7vtmlHyoxITYCgpo+UD9UFYM0WB12yJrweVBTL9JJt bEw/vodpV8o7GOxQZeTw4s2MTq7awvaU+7ls6ue7g6ggbra4UyhNdyVorfiugB4gZXt0 KDuYdgE0NQotaJA/LI0UIW72g3iiFByxEIuPoaA0jns92tBXCSepKXSLpZanvY6KzDIP fHeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3nSJt2wVIh6BPso+/5eEugChhl7K9J9KvL28I6hU2Mc=; b=O3mfmG7ZaoKhHieCjx/LPT44seWZadlt/NX39bk3XFJMFXnPpxakNhXblao0DfYy1b 0JQrVlnh1Kp7k2w74h1+UaNXfWcnVY0v5xUshdkVjS5SR6aWwURZNfzGdJokJMJ2SA1T ZNYWtCrqE8lNSboW0C0dxCIoG48e3IO06GM3TpsupZ5O0VouPQyfllmvFz3Z8DgKBxbt sZNdcF3C2Ezziuecjfe7XCvDEVhAh21mYOEHLPDC0GGYHbhkfQEJwx3HuzMrdVfFXNJx sUC2Cs+oTQPvnNX+cRq79HUzcLxKInoFlpQqyRhye0v6lIC9liA2uSzg+bVL1b8G3EUi p0SA== X-Gm-Message-State: AOAM532wy7vf+LsZky9OstLRxEzTVqnf24zvbmg5JLWlJ3BKatQBK1rj +cZx/XXFN0u6vO4WdE745XyE/NEsxAd9/Ch1a9wq1Q== X-Google-Smtp-Source: ABdhPJwvdbge9dFU6ODLriZxUOU3MC1qOuSsWZfB9Ag10DwHavakZNHULRmsBxP5cWZD1feem6Z/2nFZ3dkKu0EzFlA= X-Received: by 2002:a9d:600a:: with SMTP id h10mr21242926otj.144.1626776260256; Tue, 20 Jul 2021 03:17:40 -0700 (PDT) MIME-Version: 1.0 References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-7-qperret@google.com> In-Reply-To: <20210719104735.3681732-7-qperret@google.com> From: Fuad Tabba Date: Tue, 20 Jul 2021 11:17:03 +0100 Message-ID: Subject: Re: [PATCH 06/14] KVM: arm64: Tolerate re-creating hyp mappings to set ignored bits To: Quentin Perret Cc: kernel-team@android.com, qwandor@google.com, maz@kernel.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hi Quentin, On Mon, Jul 19, 2021 at 11:47 AM Quentin Perret wrote: > > The current hypervisor stage-1 mapping code doesn't allow changing an > existing valid mapping. Relax this condition by allowing changes that > only target ignored bits, as that will soon be needed to annotate shared > pages. > > Signed-off-by: Quentin Perret > --- > arch/arm64/kvm/hyp/pgtable.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index a0ac8c2bc174..34cf67997a82 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -362,6 +362,17 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > return 0; > } > > +static bool hyp_pte_needs_update(kvm_pte_t old, kvm_pte_t new) > +{ > + if (old == new) > + return false; > + > + if (!kvm_pte_valid(old)) > + return true; > + > + return !WARN_ON((old ^ new) & ~KVM_PTE_LEAF_ATTR_IGNORED); Wouldn't this return false if both ignored and non-ignored bits were different, or is that not possible (judging by the WARN_ON)? If it is, then it would need an update, wouldn't it? Thanks, /fuad > +} > + > static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > kvm_pte_t *ptep, struct hyp_map_data *data) > { > @@ -371,9 +382,12 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > if (!kvm_block_mapping_supported(addr, end, phys, level)) > return false; > > - /* Tolerate KVM recreating the exact same mapping */ > + /* > + * Tolerate KVM recreating the exact same mapping, or changing ignored > + * bits. > + */ > new = kvm_init_valid_leaf_pte(phys, data->attr, level); > - if (old != new && !WARN_ON(kvm_pte_valid(old))) > + if (hyp_pte_needs_update(old, new)) > smp_store_release(ptep, new); > > data->phys += granule; > -- > 2.32.0.402.g57bb445576-goog > _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.2 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 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 46982C07E95 for ; Tue, 20 Jul 2021 10:19:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 0EDE260FE9 for ; Tue, 20 Jul 2021 10:19:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EDE260FE9 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=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VOLSuoa+pTb70jzQU/lSF+oBq7JeFIa9wGOtEjAPg4c=; b=tRYxEJ4XxqbLrp KZaPdpU7AHIegP0nM4r7NyIUYmRxHnK6vAmesRIa5zqhk9GksnqJWonvLsy9+n5rjQwhiCyuaYPiW SdAobbrL3sc5AfmUkXT+3lLshn078cqXu4JI2b7EELzWoINx7+H1c95BZ4CkG5vpsStn8wH0OofpJ hb8vDKmEZUQ2W1aQvXcTTP2vwqTFqEDk+hDO1GBL+zTo2NQV4RxQHi08sbScuzgEQVkjo44hA7XMQ h3xpUuPTzwY8NMqpLJ4jDmi63/scx8sM5dimbGKbii+i2RMomBkXxtcgagtC78SJQ6n7a9SbRkpD/ Sy7Ao6ukh3M7yCofxrRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5mot-00CUp2-Qp; Tue, 20 Jul 2021 10:17:48 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5moq-00CUoX-In for linux-arm-kernel@lists.infradead.org; Tue, 20 Jul 2021 10:17:46 +0000 Received: by mail-ot1-x333.google.com with SMTP id o72-20020a9d224e0000b02904bb9756274cso21091929ota.6 for ; Tue, 20 Jul 2021 03:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3nSJt2wVIh6BPso+/5eEugChhl7K9J9KvL28I6hU2Mc=; b=GYmt8m/9xcpbfJpN+JDFmpyQSiDjQCb2/C4Arok72cqv+29SFuIJytkUrLba4/h+yJ S5kStZCpS/bjSyihG7MOnHe7cl6OnFiucpWXpykGdrB5sdipCaSB8Mr5r8RirOqjZZeX WfF7zxiBwr002UhhGIDgI6mfde7vtmlHyoxITYCgpo+UD9UFYM0WB12yJrweVBTL9JJt bEw/vodpV8o7GOxQZeTw4s2MTq7awvaU+7ls6ue7g6ggbra4UyhNdyVorfiugB4gZXt0 KDuYdgE0NQotaJA/LI0UIW72g3iiFByxEIuPoaA0jns92tBXCSepKXSLpZanvY6KzDIP fHeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3nSJt2wVIh6BPso+/5eEugChhl7K9J9KvL28I6hU2Mc=; b=FY9BySAXhH2YMc+zOmHY5X1kEvNdtVTZ63qmLs22MV4tc4mhIMleITFOQEzK30SSro RXqlpCosaawuwWVCzs8LrsFmG4LeGtrTuhNTkLzzQt9ULr6LuCv2i/YVlhL/63p0AhF6 7kZKiAneMI6dXKvgsbcN9gG23TxN3gb8JZs6TeFYFTuj2vKv7Ry9BoeM93/udAkRkwon CQXhfHNVxUQuHCWaP1jGU6e9RB2il/T2QE67NjVHLlJ9vNEEoDqHHDTQY1NRBd8QNBHA akpUMr16CF8P+zgDlVgoiYHMC8atVD10IcThk+kXMBtbh4TWG+dO5y1hOFQEcqALVQYy vW2Q== X-Gm-Message-State: AOAM533UHUhqjzh+MxgIwI2xie8ChCQvBPAxTYFEY9D1vu92T1n669ss nk1MkW3ffsrPABxtc1U5aJ59Td/8T1tT8bieUSLNwQ== X-Google-Smtp-Source: ABdhPJwvdbge9dFU6ODLriZxUOU3MC1qOuSsWZfB9Ag10DwHavakZNHULRmsBxP5cWZD1feem6Z/2nFZ3dkKu0EzFlA= X-Received: by 2002:a9d:600a:: with SMTP id h10mr21242926otj.144.1626776260256; Tue, 20 Jul 2021 03:17:40 -0700 (PDT) MIME-Version: 1.0 References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-7-qperret@google.com> In-Reply-To: <20210719104735.3681732-7-qperret@google.com> From: Fuad Tabba Date: Tue, 20 Jul 2021 11:17:03 +0100 Message-ID: Subject: Re: [PATCH 06/14] KVM: arm64: Tolerate re-creating hyp mappings to set ignored bits To: Quentin Perret Cc: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, dbrazdil@google.com, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_031744_685793_37720498 X-CRM114-Status: GOOD ( 19.31 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Quentin, On Mon, Jul 19, 2021 at 11:47 AM Quentin Perret wrote: > > The current hypervisor stage-1 mapping code doesn't allow changing an > existing valid mapping. Relax this condition by allowing changes that > only target ignored bits, as that will soon be needed to annotate shared > pages. > > Signed-off-by: Quentin Perret > --- > arch/arm64/kvm/hyp/pgtable.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index a0ac8c2bc174..34cf67997a82 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -362,6 +362,17 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > return 0; > } > > +static bool hyp_pte_needs_update(kvm_pte_t old, kvm_pte_t new) > +{ > + if (old == new) > + return false; > + > + if (!kvm_pte_valid(old)) > + return true; > + > + return !WARN_ON((old ^ new) & ~KVM_PTE_LEAF_ATTR_IGNORED); Wouldn't this return false if both ignored and non-ignored bits were different, or is that not possible (judging by the WARN_ON)? If it is, then it would need an update, wouldn't it? Thanks, /fuad > +} > + > static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > kvm_pte_t *ptep, struct hyp_map_data *data) > { > @@ -371,9 +382,12 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > if (!kvm_block_mapping_supported(addr, end, phys, level)) > return false; > > - /* Tolerate KVM recreating the exact same mapping */ > + /* > + * Tolerate KVM recreating the exact same mapping, or changing ignored > + * bits. > + */ > new = kvm_init_valid_leaf_pte(phys, data->attr, level); > - if (old != new && !WARN_ON(kvm_pte_valid(old))) > + if (hyp_pte_needs_update(old, new)) > smp_store_release(ptep, new); > > data->phys += granule; > -- > 2.32.0.402.g57bb445576-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel