Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp241902pxb; Mon, 13 Sep 2021 18:07:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9zei0y9D0v0GC5fyT7CiJPXMiuoBKRJa3DRPB5oD/5wFUG1Cfi2UPvifPgiC6mnNd9mUp X-Received: by 2002:a05:6e02:1bc5:: with SMTP id x5mr10020380ilv.83.1631581657478; Mon, 13 Sep 2021 18:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631581657; cv=none; d=google.com; s=arc-20160816; b=r6tjbVAkzIr9oBLaI3/ioVdNjNLmjhYT3bOgPPhz5ZD0P3/cvOnn4IKQPn3VbJvEu6 LWnwMZKZefsakBUiSWFYiGCuvZedydbQzQS4TtTFY8hsHdWddmQKdxsvh6E28/rO0D3r 3TF9UtKUgucY2SL0chGopLgxxMFnfJiwDGoc/TMjOe5blu6t+XiLkPi5iJZ4NnKpLQq9 4V7gmRliAM26imX7jIiO9hL49+GQgLmDL7xD/6+253weee1ryz9WJYahDk0S4NQUGp3i 6oK2svDFmtIHrP/RiwwlfyzzQv8xAm1foWeJMf5acscF/+v0o9/YkzX480bRnU0eKja4 WR5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=S2j8r1BCKqhVhJ+8bR7t/dA2J/PIIE/Rns3zAg7zZww=; b=qqSnbYd6w6hE0TwOsQmOhZOSvUbWDo3bORuHxkKe6x2Kkq7qq1we8bDRpA90HfuY6H l8p0rOJiRDAe1Ldgt4inDPW5nApefyYBF0fvW40zhGhyab4soDS5lLuzc1GwmrjTdPeq nVsgALF6k0faYFrWLHdaC6TZU/1rhEVhe7vv/9ZKZy26aV7j52SAAfsay2M9/OBNRIzr t/Decc2GqosV+4l0pbu07TAAhNh1vK2dt1arw1lL8chMxlYEeEzLKW20XHl2hobzDUAr xreXxpfjeJgJEWAkjB6zd01DUpeNvc1iRFWuq0iJA/EQ4UmOpnGqie+p+zXdzo4ne2LV tPgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HhlIi3zO; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si8749634ilm.91.2021.09.13.18.07.26; Mon, 13 Sep 2021 18:07:37 -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=@google.com header.s=20210112 header.b=HhlIi3zO; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347852AbhIMUvM (ORCPT + 99 others); Mon, 13 Sep 2021 16:51:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244825AbhIMUvB (ORCPT ); Mon, 13 Sep 2021 16:51:01 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1177DC061574 for ; Mon, 13 Sep 2021 13:49:45 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id z19-20020a631913000000b00252ede336caso8015800pgl.4 for ; Mon, 13 Sep 2021 13:49:45 -0700 (PDT) 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=S2j8r1BCKqhVhJ+8bR7t/dA2J/PIIE/Rns3zAg7zZww=; b=HhlIi3zOq8nN2/PIzYwdWzxYruhZ3ZGEFTCukDG3CHU33zR+QnniRcYj7haQyqqB/Q ntXvSsHqHdGuqS+u451AJvAzjlVzZuPSza4IEtAhhPEryAgylWYKb8GdnjEkKkch9pzV rjeSnlBr7yQJDk1M7U37dx1o7M0nyUK1zhJTdAZ40JK48YAYyMXixVEU+d8cZOxNBss9 wzfL1WgVfX2yx/wyKTixQzdnRy4UNUaE9ZxkNEocqYyIo7B8zgwsQ1cI0PSF51cd3SIU OGfI6ZbEQpPHQkQDwyR3i+rWtdELT36/PGSG31A17wgrW1Wnal/Xj1C4SKVnCLTplgKt F/5g== 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=S2j8r1BCKqhVhJ+8bR7t/dA2J/PIIE/Rns3zAg7zZww=; b=OUSjpaorG1bqDb2ls6YJvutUIKThoQER+jmPFAqhY1Fap34PvOS2xHiKmsLUz/UiJd An4QciHqokFbUNGb+IH+M/pkAPW+qAoW7UgjCNuQsoMlaWp+6IfpQGUtzSpg6Yn3gFqs jifQf5rdcZjIDaudrGOebvRHIp99umVmBm6+xkexKFugoZK9saI2oIiG8bpFLP+sMHKf kSd3Hbj0IQKlig+Wm3QtUpQYvf2Z7x9vmEqy1Td+CnG4/AW91tLWF13V0QXbPjnBMFH1 XX9aRsIHz3qnLguEHnAJZ6xlI7U09jeiFFbJoNI672AkfKFNQWsMP+ir9M8GtfltKAy+ HZ/A== X-Gm-Message-State: AOAM531hzUTuByn4o66PFFA8aoYkxZzdeeBYjT9Y9O9I/zailtB1sCxS k45c5xM1DDqAeOOSOfVOGaLooUq6aBqL X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90b:fd7:: with SMTP id gd23mr1103667pjb.1.1631566184150; Mon, 13 Sep 2021 13:49:44 -0700 (PDT) Date: Mon, 13 Sep 2021 20:49:17 +0000 In-Reply-To: <20210913204930.130715-1-rananta@google.com> Message-Id: <20210913204930.130715-2-rananta@google.com> Mime-Version: 1.0 References: <20210913204930.130715-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v5 01/14] KVM: arm64: selftests: Add MMIO readl/writel support From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define the readl() and writel() functions for the guests to access (4-byte) the MMIO region. The routines, and their dependents, are inspired from the kernel's arch/arm64/include/asm/io.h and arch/arm64/include/asm/barrier.h. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Oliver Upton Reviewed-by: Andrew Jones --- .../selftests/kvm/include/aarch64/processor.h | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index c0273aefa63d..96578bd46a85 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -9,6 +9,7 @@ #include "kvm_util.h" #include +#include #define ARM64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ @@ -130,6 +131,49 @@ void vm_install_sync_handler(struct kvm_vm *vm, val; \ }) -#define isb() asm volatile("isb" : : : "memory") +#define isb() asm volatile("isb" : : : "memory") +#define dsb(opt) asm volatile("dsb " #opt : : : "memory") +#define dmb(opt) asm volatile("dmb " #opt : : : "memory") + +#define dma_wmb() dmb(oshst) +#define __iowmb() dma_wmb() + +#define dma_rmb() dmb(oshld) + +#define __iormb(v) \ +({ \ + unsigned long tmp; \ + \ + dma_rmb(); \ + \ + /* \ + * Courtesy of arch/arm64/include/asm/io.h: \ + * Create a dummy control dependency from the IO read to any \ + * later instructions. This ensures that a subsequent call \ + * to udelay() will be ordered due to the ISB in __delay(). \ + */ \ + asm volatile("eor %0, %1, %1\n" \ + "cbnz %0, ." \ + : "=r" (tmp) : "r" ((unsigned long)(v)) \ + : "memory"); \ +}) + +static __always_inline void __raw_writel(u32 val, volatile void *addr) +{ + asm volatile("str %w0, [%1]" : : "rZ" (val), "r" (addr)); +} + +static __always_inline u32 __raw_readl(const volatile void *addr) +{ + u32 val; + asm volatile("ldr %w0, [%1]" : "=r" (val) : "r" (addr)); + return val; +} + +#define writel_relaxed(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) +#define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) + +#define writel(v,c) ({ __iowmb(); writel_relaxed((v),(c));}) +#define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(__v); __v; }) #endif /* SELFTEST_KVM_PROCESSOR_H */ -- 2.33.0.309.g3052b89438-goog