From patchwork Thu Jan 27 03:08:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12726210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F4F0C433EF for ; Thu, 27 Jan 2022 03:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233048AbiA0DJG (ORCPT ); Wed, 26 Jan 2022 22:09:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbiA0DJF (ORCPT ); Wed, 26 Jan 2022 22:09:05 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3C62C06161C for ; Wed, 26 Jan 2022 19:09:04 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id ik14-20020a170902ab0e00b0014c84153eb0so264212plb.17 for ; Wed, 26 Jan 2022 19:09:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=y8xiYhpGFxFKO0m5kKEQAv7sJcYQ8XNaG5VWu+Ph1Do=; b=FEdpoVYgU4JntAof5I9WPwlqD9ZAVq8CUvLK6LaYoB1EHNTpqXFRq12cfq0POmb7u4 iwYEykWf5MFxuGpvTqbIeaHJmgchKLL9KC1XEH+L+9QbWZJDbn3bZc8H3/u00ZPHtr0X VuRcbdSQdY18NlDVx9MBPJBs/5uX5ghdFrbf4hHJDui+jCFIRSYmq3J+/k2aAAZQ2crs x98ADrn7phtxBIpgPUpS+kmW4QqRruyi9+Wrds4PZGFQa3+cEBJTeyV1aUaSgBE6VrRr ui92v01imlYes9h9PEykIb9PDmtvZK5kxw/IFLpZcaPVIrnzb6DRfnLa/aXe2eLRHe0a qJNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=y8xiYhpGFxFKO0m5kKEQAv7sJcYQ8XNaG5VWu+Ph1Do=; b=PF8ANe5rtOu8bvWdjHyj51lT1seOaiTdYhlOy558s3BsqFUHTJLYdToWc++K6skBA8 vV9YuFfLlKLn5f0lqerLH2DDoLtcmWC2jsAujtDkllsy00t+OBcC6CVcSc4/GGaWr51s Oh8EXgTdb4UrMP3dkGJZJ8B1+4zedg6HGara2PdftGRglKGN+LgfcLKRTo3EZ5sEkEDD gfNWb+mhz7gXEdgjAckejTmo1q9Z45xI4ZuFHOW103J+ZpoTl5xeSQw/U9ZTZeG7K2ku qTRXN8ZZBkXwXbJ/L/aSLH6OWN/1TZN5fpZJ+cQSH2mk5Z7+0pCvLf6b5Zw4JBk9+T2Q tQbA== X-Gm-Message-State: AOAM531UXnSO+rlWeGD3sJPNr54BrwW5/AFlQ730BayqGzcluRE8DNsk EMaOXL2JMDvLP0TXwlvvzrgf6KRuDGnkChdIrzGnZWTDZaVxo2VQD3NX7sop8vS4s7lqk4wonEQ Nc5ZkSK+sYbQXsV7OnjcIMObHu+PUnr/Ot16BhIyUDuJCu/UFrTm8zgwRbjO5BwM= X-Google-Smtp-Source: ABdhPJxmaasoGq2r0NV2rJ2gM2vKa93DMcKl2L+uSImOPLZd8TXUisygF0ba4SClaxCVIoaZZ4OxxQkMcxetyw== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a63:d943:: with SMTP id e3mr1310151pgj.427.1643252944210; Wed, 26 Jan 2022 19:09:04 -0800 (PST) Date: Wed, 26 Jan 2022 19:08:54 -0800 In-Reply-To: <20220127030858.3269036-1-ricarkol@google.com> Message-Id: <20220127030858.3269036-2-ricarkol@google.com> Mime-Version: 1.0 References: <20220127030858.3269036-1-ricarkol@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 1/5] kvm: selftests: aarch64: fix assert in gicv3_access_reg From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com Cc: maz@kernel.org, Paolo Bonzini , oupton@google.com, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The val argument in gicv3_access_reg can have any value when used for a read, not necessarily 0. Fix the assert by checking val only for writes. Signed-off-by: Ricardo Koller Reported-by: Reiji Watanabe Cc: Andrew Jones Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/lib/aarch64/gic_v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c b/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c index 00f613c0583c..e4945fe66620 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c +++ b/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c @@ -159,7 +159,7 @@ static void gicv3_access_reg(uint32_t intid, uint64_t offset, uint32_t cpu_or_dist; GUEST_ASSERT(bits_per_field <= reg_bits); - GUEST_ASSERT(*val < (1U << bits_per_field)); + GUEST_ASSERT(!write || *val < (1U << bits_per_field)); /* Some registers like IROUTER are 64 bit long. Those are currently not * supported by readl nor writel, so just asserting here until then. */ From patchwork Thu Jan 27 03:08:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12726211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BEDBC433EF for ; Thu, 27 Jan 2022 03:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233589AbiA0DJI (ORCPT ); Wed, 26 Jan 2022 22:09:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233080AbiA0DJG (ORCPT ); Wed, 26 Jan 2022 22:09:06 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C51C0C06161C for ; Wed, 26 Jan 2022 19:09:06 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id p5-20020a170902bd0500b00148cb2d29ecso814998pls.4 for ; Wed, 26 Jan 2022 19:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lqWGfh2BJMERTwHvF+7RFLuQxcilmmI6PUG6asomKXE=; b=U/7s/RD/eWobrbk6Ldg3LkBFZ1PgmOUJlVBFTuh99tKfbEgEQWP4jPoq38c0nptkxy 7t3su/tNuMcY5Ot+znpjZd4STvjf9VIezzUO40l2zRyqnyagTjuHvItXTkUPgxcIazGp xswQhIsvCV0mfnifIKbouhGkN0Xs8TfHfCi3OVkvw2HwaSjDkcV4GhLTH1YWsaLnkkKq xGmYWxZS/YfymhudibefhxEqrAertW+N5r68/tsC9VBmOqPEgjPyXe5ayTBTlnlowM7X xt8sOOFma55MRiH85uByCVjk6fqnNf/PWzqS0t8yHV5LLtgwMU31t47Wa+m5j64VTDM9 SdMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lqWGfh2BJMERTwHvF+7RFLuQxcilmmI6PUG6asomKXE=; b=pKW1/g1VRxIX/2zJvr8a/+d4TdwiFMTv+8tAD6RCQqSHYuPOYKm3zkiUktCMA+kVs6 qzdcbwx7+uNsTo1Iee+pbr0AZn01cHKnCazeUudyeTNjXQXNwJ5qshKysz0JMKpmIgdH fCQzVbFGcHYQabdWxNa8XmUbmOyat6g2Im0YG1SuqTCvZtOkoSqCBweJnbGa9yZPbRli 0/Nk5qjZVJkuAyS/CIxEcq7OPkIyUhMZ4Q2JM0lM4AgERQAR1Dh/etVSpoYAr6lvd7SS YF2gAajBIMss0kvQOUZCx1xypb6uZs6uSXtfQSUoOddvQP6QdFWevYB0LuuRyJ7rxXat G5Lg== X-Gm-Message-State: AOAM531dKOxBSWU0V98Sn/MOEF2r2UpPUjTu9Ewa0MayJ/k2gGxMfwvb GOT2mJGWk75ssNSiUxtI/b95ecZhqj1yDqC5XunJQYLdyUPdAAkEEpPvp00YnNHSBxcnTzezi7D ZhsTj1PCE6QlQGy2lGoTx5/4E43yGJk5gACpLeWnA7SlLq2R2bHbVie7S3WaUa0c= X-Google-Smtp-Source: ABdhPJx5gWsEp7INU7scxngnVF9QetFYhYL4j1t6IkPIGmvXy8Dl4Zych8ub9e0y2Xeaod39U96Ah8zx+33LvA== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a17:903:1250:: with SMTP id u16mr1663963plh.126.1643252946183; Wed, 26 Jan 2022 19:09:06 -0800 (PST) Date: Wed, 26 Jan 2022 19:08:55 -0800 In-Reply-To: <20220127030858.3269036-1-ricarkol@google.com> Message-Id: <20220127030858.3269036-3-ricarkol@google.com> Mime-Version: 1.0 References: <20220127030858.3269036-1-ricarkol@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 2/5] kvm: selftests: aarch64: pass vgic_irq guest args as a pointer From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com Cc: maz@kernel.org, Paolo Bonzini , oupton@google.com, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The guest in vgic_irq gets its arguments in a struct. This struct used to fit nicely in a single register so vcpu_args_set() was able to pass it by value by setting x0 with it. Unfortunately, this args struct grew after some commits and some guest args became random (specically kvm_supports_irqfd). Fix this by passing the guest args as a pointer (after allocating some guest memory for it). Signed-off-by: Ricardo Koller Reported-by: Reiji Watanabe Cc: Andrew Jones Reviewed-by: Andrew Jones --- .../testing/selftests/kvm/aarch64/vgic_irq.c | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing/selftests/kvm/aarch64/vgic_irq.c index e6c7d7f8fbd1..b701eb80128d 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -472,10 +472,10 @@ static void test_restore_active(struct test_args *args, struct kvm_inject_desc * guest_restore_active(args, MIN_SPI, 4, f->cmd); } -static void guest_code(struct test_args args) +static void guest_code(struct test_args *args) { - uint32_t i, nr_irqs = args.nr_irqs; - bool level_sensitive = args.level_sensitive; + uint32_t i, nr_irqs = args->nr_irqs; + bool level_sensitive = args->level_sensitive; struct kvm_inject_desc *f, *inject_fns; gic_init(GIC_V3, 1, dist, redist); @@ -484,11 +484,11 @@ static void guest_code(struct test_args args) gic_irq_enable(i); for (i = MIN_SPI; i < nr_irqs; i++) - gic_irq_set_config(i, !args.level_sensitive); + gic_irq_set_config(i, !level_sensitive); - gic_set_eoi_split(args.eoi_split); + gic_set_eoi_split(args->eoi_split); - reset_priorities(&args); + reset_priorities(args); gic_set_priority_mask(CPU_PRIO_MASK); inject_fns = level_sensitive ? inject_level_fns @@ -497,17 +497,17 @@ static void guest_code(struct test_args args) local_irq_enable(); /* Start the tests. */ - for_each_supported_inject_fn(&args, inject_fns, f) { - test_injection(&args, f); - test_preemption(&args, f); - test_injection_failure(&args, f); + for_each_supported_inject_fn(args, inject_fns, f) { + test_injection(args, f); + test_preemption(args, f); + test_injection_failure(args, f); } /* Restore the active state of IRQs. This would happen when live * migrating IRQs in the middle of being handled. */ - for_each_supported_activate_fn(&args, set_active_fns, f) - test_restore_active(&args, f); + for_each_supported_activate_fn(args, set_active_fns, f) + test_restore_active(args, f); GUEST_DONE(); } @@ -739,6 +739,7 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split) int gic_fd; struct kvm_vm *vm; struct kvm_inject_args inject_args; + vm_vaddr_t args_gva; struct test_args args = { .nr_irqs = nr_irqs, @@ -757,7 +758,9 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split) vcpu_init_descriptor_tables(vm, VCPU_ID); /* Setup the guest args page (so it gets the args). */ - vcpu_args_set(vm, 0, 1, args); + args_gva = vm_vaddr_alloc_page(vm); + memcpy(addr_gva2hva(vm, args_gva), &args, sizeof(args)); + vcpu_args_set(vm, 0, 1, args_gva); gic_fd = vgic_v3_setup(vm, 1, nr_irqs, GICD_BASE_GPA, GICR_BASE_GPA); From patchwork Thu Jan 27 03:08:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12726212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F1A1C433F5 for ; Thu, 27 Jan 2022 03:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235394AbiA0DJK (ORCPT ); Wed, 26 Jan 2022 22:09:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233194AbiA0DJJ (ORCPT ); Wed, 26 Jan 2022 22:09:09 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 961EDC06161C for ; Wed, 26 Jan 2022 19:09:08 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id n9-20020a17090a73c900b001b5cafefa27so996514pjk.2 for ; Wed, 26 Jan 2022 19:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QPrlx7WHIAMxZ0O9Mmyf5U2YjXNGMzfcwUvdJYaS1zI=; b=fhA0NR/VPVJDiuNh+ZXtLY1vNHbmDxiynQqQuaOu7UYvHGuxaZd6jVZjI/ea+aGRwZ 61lOCTcrzAyX43PsleAzNi9Xm9/YZtw/GpaAXIgFVgcGIGNCu5/JR7VV5J8GwaxKJu+f tjuMBjRXn16zC+uIme146UtoZbzn29+gDFVdCKuwOyzetDQsnVZXi4CWqHT10qBY/XvG Aw/G8lcK+2nWPRlOHithMqFBQMVNb32esoa8sXHdak3D4GfeGH68iUSCgQgGxg9HDlgT J2CFep8xfZ9/YMi6gK60jdN4//1bfio32WkuqvdXpJUE4d9tP8FpDEJn4VTyeKBjRpFw INLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QPrlx7WHIAMxZ0O9Mmyf5U2YjXNGMzfcwUvdJYaS1zI=; b=P6xOYkvmoYmgXn/Fg+QO3GrPCJFFQD97dANrvkb5CkNrkW1WBcHYUWquvRYETgTu8k xsJ0sCpT4R907mXjFHZWDy0UxVMrIwCPF+R+S4+nMEGsxu7Um6iJvoLjQ/pMKq1PNktz 5mdOGo7io2Sb7SBXt29lPTyrDOtPWI0stubdQSEpKdwKV63p/+N/hGp2K2JINK70VbQN vYI5S/bJU6GzakDpQ92bLP9DSAAlbDEtS1V0uPLiiFxSyjjEsGz7a+lZ9spoptwBZ07N 7t8nto9BVF9wFNA0TLTOXbr7qSpV1hLo0jTjuoIdZ5Xij2C/wvgvkXHyrxFk0/CskkYM U6jw== X-Gm-Message-State: AOAM531tT73bXKKmSI1kSAHGzMARSei35qUW7xP9ELnzqxTk5JPXDBOe pWBlUtS+S166H9BUjDb2WA3mFgup2oHiOwjXptNutLcwo5rFmquo44eXr5r94rOX/3wMFJh5uAn Cb10ah3xRVZYWETZ2xYm9oIK1DYtxLh0/mTz9I65Kc0h9nedJuzaZJJAexHjlJH4= X-Google-Smtp-Source: ABdhPJwfM10RSJpC/YJ0gxNH0zBPwJaj1dw5B5vZEVnAFjcJjtuWKaQNHlWvaJebRY8Yo3QV6+aXBzoV+0HnRQ== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a17:90a:74c2:: with SMTP id p2mr2043435pjl.155.1643252947940; Wed, 26 Jan 2022 19:09:07 -0800 (PST) Date: Wed, 26 Jan 2022 19:08:56 -0800 In-Reply-To: <20220127030858.3269036-1-ricarkol@google.com> Message-Id: <20220127030858.3269036-4-ricarkol@google.com> Mime-Version: 1.0 References: <20220127030858.3269036-1-ricarkol@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 3/5] kvm: selftests: aarch64: fix the failure check in kvm_set_gsi_routing_irqchip_check From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com Cc: maz@kernel.org, Paolo Bonzini , oupton@google.com, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org kvm_set_gsi_routing_irqchip_check(expect_failure=true) is used to check the error code returned by the kernel when trying to setup an invalid gsi routing table. The ioctl fails if "pin >= KVM_IRQCHIP_NUM_PINS", so kvm_set_gsi_routing_irqchip_check() should test the error only when "intid >= KVM_IRQCHIP_NUM_PINS+32". The issue is that the test check is "intid >= KVM_IRQCHIP_NUM_PINS", so for a case like "intid = KVM_IRQCHIP_NUM_PINS" the test wrongly assumes that the kernel will return an error. Fix this by using the right check. Signed-off-by: Ricardo Koller Reported-by: Reiji Watanabe Cc: Andrew Jones --- tools/testing/selftests/kvm/aarch64/vgic_irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing/selftests/kvm/aarch64/vgic_irq.c index b701eb80128d..0106fc464afe 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -573,8 +573,8 @@ static void kvm_set_gsi_routing_irqchip_check(struct kvm_vm *vm, kvm_gsi_routing_write(vm, routing); } else { ret = _kvm_gsi_routing_write(vm, routing); - /* The kernel only checks for KVM_IRQCHIP_NUM_PINS. */ - if (intid >= KVM_IRQCHIP_NUM_PINS) + /* The kernel only checks e->irqchip.pin >= KVM_IRQCHIP_NUM_PINS */ + if (((uint64_t)intid + num - 1 - MIN_SPI) >= KVM_IRQCHIP_NUM_PINS) TEST_ASSERT(ret != 0 && errno == EINVAL, "Bad intid %u did not cause KVM_SET_GSI_ROUTING " "error: rc: %i errno: %i", intid, ret, errno); From patchwork Thu Jan 27 03:08:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12726213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3BF2C433FE for ; Thu, 27 Jan 2022 03:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235491AbiA0DJL (ORCPT ); Wed, 26 Jan 2022 22:09:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235484AbiA0DJK (ORCPT ); Wed, 26 Jan 2022 22:09:10 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 549F6C061747 for ; Wed, 26 Jan 2022 19:09:10 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id z20-20020aa791d4000000b004bd024eaf19so863410pfa.16 for ; Wed, 26 Jan 2022 19:09:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rhk6j9gRndhFt7iP2TVyhddxWPk9PhYFxYC5q91Zsdg=; b=SlbmbPBXQl3T5K8eTfGmwRXq6TK2VXIVS9+ikrXB+LONl76upQutz96Nnbl3V8s4AK IsnEVOel9bzyKLraIAKq45m0mEXDhmGyD9mbeTpQnae4yLM6+08L/1Dsd3csDVHb+Iy7 hfjk+5eAvMV6MCPp2WEwM/tCk6oD4iK3M8CbfHr8tQy5KsQd5OHlpXwNBKWTxhL+UNeE KkCqs13x0XwW2M1PFzdHP8ATcKS3W6+ZbUiktiW3h4Hza55o7irQFviycZDyEukr3Mar Bg9lPj2EYoewe+nx1A6b1sde0Fe5/OBJANfTm/bpDIFlt8PPULq67cWQVEbqDloBbPc8 3ZtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rhk6j9gRndhFt7iP2TVyhddxWPk9PhYFxYC5q91Zsdg=; b=0dRxdcn0JLDf6c/TD3rmOc/2nJbQq6tsFAS74G0uESBhSN+F/ehDqmSOqfHG2vFJCt 1KeAgCpCXjej1BMa+mB+liYgg0A2rI5FjpgIO7Cb9yPQ20Higg/raoRGLFwngM1MwOA/ +dYYSEnVxYuZVs+OmNSOXaS1kQgmylhWYr91+Wu3q23t7fJej2ZCVsDogAxWky6nS9AG i8VW99AFxOJFBRliF5CTEH0LUIbXAkNSOYZ5eO/FqaIVdSolCybhmzuZusjS1n4y2th1 snW6Q9deB9yGqKKsDcmqtmlOPZcAHU941WgIPO2z8OEczgXWZZMWYjHq1PXrjRkQIL0/ MJPw== X-Gm-Message-State: AOAM533MgHL6MkRfgJluzqdiEz112VZQtlD1kap/JQ6mjRo10XEOqbrp hX8dHeHZvCty5WqN8pGIrEieo8rnX0x5z67GQhD2+abAYNzmceimVGUqu9OB2Nm8RHuQvC+URPD n/xTK2UTXpwW+ipdnXkVEBd97uibFYDanK6l9iM3zaYV8gqU23TWH7mRBc+/Rm7g= X-Google-Smtp-Source: ABdhPJwZTHG96HGAEawR6UBfAwQW4vQacgQNfKo91OhKJ5XB4h7q2TSUyIekjn2aqbEm8YuK2Gbf0EWzVhIrtQ== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a05:6a00:10c6:: with SMTP id d6mr1723120pfu.42.1643252949597; Wed, 26 Jan 2022 19:09:09 -0800 (PST) Date: Wed, 26 Jan 2022 19:08:57 -0800 In-Reply-To: <20220127030858.3269036-1-ricarkol@google.com> Message-Id: <20220127030858.3269036-5-ricarkol@google.com> Mime-Version: 1.0 References: <20220127030858.3269036-1-ricarkol@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 4/5] kvm: selftests: aarch64: fix some vgic related comments From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com Cc: maz@kernel.org, Paolo Bonzini , oupton@google.com, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fix the formatting of some comments and the wording of one of them (in gicv3_access_reg). Signed-off-by: Ricardo Koller Reported-by: Reiji Watanabe Cc: Andrew Jones Reviewed-by: Andrew Jones Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/aarch64/vgic_irq.c | 12 ++++++++---- tools/testing/selftests/kvm/lib/aarch64/gic_v3.c | 10 ++++++---- tools/testing/selftests/kvm/lib/aarch64/vgic.c | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing/selftests/kvm/aarch64/vgic_irq.c index 0106fc464afe..f0230711fbe9 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -306,7 +306,8 @@ static void guest_restore_active(struct test_args *args, uint32_t prio, intid, ap1r; int i; - /* Set the priorities of the first (KVM_NUM_PRIOS - 1) IRQs + /* + * Set the priorities of the first (KVM_NUM_PRIOS - 1) IRQs * in descending order, so intid+1 can preempt intid. */ for (i = 0, prio = (num - 1) * 8; i < num; i++, prio -= 8) { @@ -315,7 +316,8 @@ static void guest_restore_active(struct test_args *args, gic_set_priority(intid, prio); } - /* In a real migration, KVM would restore all GIC state before running + /* + * In a real migration, KVM would restore all GIC state before running * guest code. */ for (i = 0; i < num; i++) { @@ -503,7 +505,8 @@ static void guest_code(struct test_args *args) test_injection_failure(args, f); } - /* Restore the active state of IRQs. This would happen when live + /* + * Restore the active state of IRQs. This would happen when live * migrating IRQs in the middle of being handled. */ for_each_supported_activate_fn(args, set_active_fns, f) @@ -840,7 +843,8 @@ int main(int argc, char **argv) } } - /* If the user just specified nr_irqs and/or gic_version, then run all + /* + * If the user just specified nr_irqs and/or gic_version, then run all * combinations. */ if (default_args) { diff --git a/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c b/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c index e4945fe66620..263bf3ed8fd5 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c +++ b/tools/testing/selftests/kvm/lib/aarch64/gic_v3.c @@ -19,7 +19,7 @@ struct gicv3_data { unsigned int nr_spis; }; -#define sgi_base_from_redist(redist_base) (redist_base + SZ_64K) +#define sgi_base_from_redist(redist_base) (redist_base + SZ_64K) #define DIST_BIT (1U << 31) enum gicv3_intid_range { @@ -105,7 +105,8 @@ static void gicv3_set_eoi_split(bool split) { uint32_t val; - /* All other fields are read-only, so no need to read CTLR first. In + /* + * All other fields are read-only, so no need to read CTLR first. In * fact, the kernel does the same. */ val = split ? (1U << 1) : 0; @@ -160,8 +161,9 @@ static void gicv3_access_reg(uint32_t intid, uint64_t offset, GUEST_ASSERT(bits_per_field <= reg_bits); GUEST_ASSERT(!write || *val < (1U << bits_per_field)); - /* Some registers like IROUTER are 64 bit long. Those are currently not - * supported by readl nor writel, so just asserting here until then. + /* + * This function does not support 64 bit accesses. Just asserting here + * until we implement readq/writeq. */ GUEST_ASSERT(reg_bits == 32); diff --git a/tools/testing/selftests/kvm/lib/aarch64/vgic.c b/tools/testing/selftests/kvm/lib/aarch64/vgic.c index b3a0fca0d780..79864b941617 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/vgic.c +++ b/tools/testing/selftests/kvm/lib/aarch64/vgic.c @@ -150,7 +150,8 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid, attr += SZ_64K; } - /* All calls will succeed, even with invalid intid's, as long as the + /* + * All calls will succeed, even with invalid intid's, as long as the * addr part of the attr is within 32 bits (checked above). An invalid * intid will just make the read/writes point to above the intended * register space (i.e., ICPENDR after ISPENDR). From patchwork Thu Jan 27 03:08:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12726214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1511C4332F for ; Thu, 27 Jan 2022 03:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235507AbiA0DJN (ORCPT ); Wed, 26 Jan 2022 22:09:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233194AbiA0DJM (ORCPT ); Wed, 26 Jan 2022 22:09:12 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F2C9C06173B for ; Wed, 26 Jan 2022 19:09:12 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id z37-20020a056a001da500b004c74e3fd644so895886pfw.1 for ; Wed, 26 Jan 2022 19:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GwfeejbMqNEQvaZ8Yfe9ml4jBewW/ulWJB+/b/aTwrs=; b=EtpS3gSBZUOjBB1L/nudYXj30b9atzdjUMoj0Vv7eotLi8QKfuVja6weD7hkUnZI0v jftGfz5POew9BfPZJCZpWWTYSQUgj9hZNhEmXqLLReVz1zIy8PO2r9qhg/ZY1aYPlqUn Qrwygd5W2/GdFzsPv3b8dlZ7+CF8A3y0ctD18o8RywKqD0Us6tq/eClsMvWSERUqEolK GStpjjO3ZcLhQIpM81/O48PGIOdpJVk0qfgBwH1NFjLf8kR4xu7EyNDj3mdLqxVcwAZJ eF/z8aW8VLIHxZInFiBqS7QkFEMQrVg4GGZnUrHi0dPtueK3M+TmevW1KNI5aN3wwAXH /zIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GwfeejbMqNEQvaZ8Yfe9ml4jBewW/ulWJB+/b/aTwrs=; b=VjOZ9rSS3ri6Hq11MX7xMeDnze7sMy3b2pZWUxyZsChCQKQxZFQEyOlsm29Go4JL9Z If+xYCPnl3FxNWHOCITKGWXOZlc+N/+xWx4Tpq+RyhaiKZQm2Vo9NAv9kuIafQgzk6ZI CKQuT4qHAMOIjrwDZTlXvi2uZv3WdeXRBsw2M9YTFN8cOkIagx9I4SwziSGTDQy6xjIb omTl7Durqk00Zn4U36ZG6TO5YUEsrD7zpXGBMOn1KBPol5XySXOF/yEDYyTZpAlTEp41 9QUpku9K5z0de9i3DVlHeqLAVW1w7oaGLrVtGMuDGWiOa8y9YVDyT6NhdqOAQ3NHMiqy rKAA== X-Gm-Message-State: AOAM532mfToFY8VMVAANwTkAAeY/8bPaYokn5ahLswpowo93Ezj5Yi+9 nsvvpqyJHQhGpo4vpSJX1+b9ep+ZE2jbaDewesfn2wW3cn0xbELDHFyGaNywL5qCx/gYJLd0TEc 6QMIjrCI2qhYM+R8LGeSr6AWjd58vAbqMoGJXFFOsNyA30Qyw+T12hojetPpeN+M= X-Google-Smtp-Source: ABdhPJy3JpRpBg4WMXBaYNzVrdWKDl4Dc5lDHaJc1a/ZjIUD9OyrnUNOAFFGNGVpScKQcaVXo9pxXppP2Sh1oA== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a17:90b:4d82:: with SMTP id oj2mr1328529pjb.1.1643252951408; Wed, 26 Jan 2022 19:09:11 -0800 (PST) Date: Wed, 26 Jan 2022 19:08:58 -0800 In-Reply-To: <20220127030858.3269036-1-ricarkol@google.com> Message-Id: <20220127030858.3269036-6-ricarkol@google.com> Mime-Version: 1.0 References: <20220127030858.3269036-1-ricarkol@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 5/5] kvm: selftests: aarch64: use a tighter assert in vgic_poke_irq() From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, drjones@redhat.com Cc: maz@kernel.org, Paolo Bonzini , oupton@google.com, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vgic_poke_irq() checks that the attr argument passed to the vgic device ioctl is sane. Make this check tighter by moving it to after the last attr update. Signed-off-by: Ricardo Koller Reported-by: Reiji Watanabe Cc: Andrew Jones Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/lib/aarch64/vgic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/aarch64/vgic.c b/tools/testing/selftests/kvm/lib/aarch64/vgic.c index 79864b941617..f365c32a7296 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/vgic.c +++ b/tools/testing/selftests/kvm/lib/aarch64/vgic.c @@ -138,9 +138,6 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid, uint64_t val; bool intid_is_private = INTID_IS_SGI(intid) || INTID_IS_PPI(intid); - /* Check that the addr part of the attr is within 32 bits. */ - assert(attr <= KVM_DEV_ARM_VGIC_OFFSET_MASK); - uint32_t group = intid_is_private ? KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : KVM_DEV_ARM_VGIC_GRP_DIST_REGS; @@ -150,6 +147,9 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid, attr += SZ_64K; } + /* Check that the addr part of the attr is within 32 bits. */ + assert((attr & ~KVM_DEV_ARM_VGIC_OFFSET_MASK) == 0); + /* * All calls will succeed, even with invalid intid's, as long as the * addr part of the attr is within 32 bits (checked above). An invalid