Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp100982pxb; Wed, 8 Sep 2021 18:41:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOPT+VSqaMvfZQI/ruHmCRPOClOlF24K4Nbew3/MaT0ptZ320E8DCC2YwN7B0nl+eS+SNZ X-Received: by 2002:a02:2a88:: with SMTP id w130mr513925jaw.60.1631151717980; Wed, 08 Sep 2021 18:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631151717; cv=none; d=google.com; s=arc-20160816; b=bhakhKcsdB72o6lTrKsGGM83hhLUCCIjN2Eqx8U7jdyZy6Q73To5+q9BtG3q3Cxi2z 0fkg/u89vERMH7IxMqMjm8Mjd19PCCuk8rvYk4KpkZVJfgjU2vpQGk33AJToN4PLqcnZ wUCRD5Hh1wj6TCkHqg6PpAouvI7YJfj0maQFSYrr6MP92JU8lkAqynmUylxltppMBoa2 UojZmqqZJercjmM8bjRQrlsaalvGe+EysuVNIgqLJwy3K1YLKWZLJjXdBZ2pGjnDtGgk NrOUJ8Yv7QNVm6lT0jzys1aCZlNuZSWKDkWmPs7J3pugBl1btW/T8HyqYN+2uhLzAwmj 2LQg== 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=j0qpPBycoBdEl6sY/API9Q0J9uLD1RrCFMtLgmLF8gE=; b=utuCyqHXEdb5dMcuysbW/Q6YwFLjgO/Zv2IzT639+brcD+XV/xtAjNpUrd6+F+EVxU G/AxWY7PQdbwKLCxN+nrixsqMg2//mZqoHTITPORQagKyHua0/jDdfOa34+CrQ5SQLU/ cJVJhFAq5duXSTVuiZsjna+7z2VRFaGCWMHEsdbi/T1B0wbMwQHr7oh4ZkSn/NuhMKw6 MTopIMTu4WCbxqc8Wnv44QqWRLskxKn1imxg2pD7OM718jbgRC7G/gdOnnZktT+1Zw+a 9DpxZKfI7amaplP6RqFyLQ4A/+XjshwA4w7pNQafNfvYZVal9DJN8Z0T+1UzeY4S9C+D 3TPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bUoqxmY7; 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 a4si286147ilm.68.2021.09.08.18.41.46; Wed, 08 Sep 2021 18:41:57 -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=bUoqxmY7; 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 S1349381AbhIIBjl (ORCPT + 99 others); Wed, 8 Sep 2021 21:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349304AbhIIBjh (ORCPT ); Wed, 8 Sep 2021 21:39:37 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EF41C061575 for ; Wed, 8 Sep 2021 18:38:27 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id q13-20020a05620a038d00b003d38f784161so683050qkm.8 for ; Wed, 08 Sep 2021 18:38:27 -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=j0qpPBycoBdEl6sY/API9Q0J9uLD1RrCFMtLgmLF8gE=; b=bUoqxmY7HcmvG77dTImuqBEdab2qMSQs5HoUsLegW8AXIk0EiUpM0rSu7+Gqc8+/Sh c4vT1Q+sMeqS9Kv4psB5uhRLECiDwVC/aaywZs7SOoiBsKB9nKRfqMQnmXIGBAZB36ty TotP3WKaMcqup3lpWAOdv16aJgj5UYXA1GUb2oWWY20junH9Ek/ijWzjjDAUAGeioc9o QeXTQQ2zm52bGdsUcUezcNKX6oXBLdrpwJEAE+QHw/GjeN4q7BUly9Kmrm6j62aXf5Kk h710sw9Ywaf2DTClb8udsY+af81ykVYyKQFSW0JFvR2Vj9xbZq+qxByJ6yiEkotWXpnl QYbQ== 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=j0qpPBycoBdEl6sY/API9Q0J9uLD1RrCFMtLgmLF8gE=; b=kyvlhQVgp47lu2YuTEqEFg68hYvimFDz6iZrbD8DZxYtUNMVVUjKNEFkrTMAtbZb1b jj6eFUr7xpXOnGTuQEKllY6LF/JA3vMdNPywo5yuTOqTsSjC3lI9rtNB8wnM1KAzHGa5 yCuLCH/Is+0LXajO1PLfftGhLpFeskOaOxsGhwCAph7d9XUFLM/vKb9th9BteImuDrB6 dyOEEHiW5X+vsO2Wm0FQ1yCNXgW9vcDPUzSEHVceURTVct6B7/5eMs5WOI0KdKTYu+Kc td2zlDTT0l0NGgciGcIId/NTcxschAf/YNVQkpGK0kgTAiow4Oa7pV23BzOdxgda7Edz Jn2Q== X-Gm-Message-State: AOAM530b+uZnUAP11jnFq7SO9zPSGSOCFZrl5Rk5p522AWNA7TBUnb36 OIVHjvPED8i9ZIm85t/BHDFM22X1J5fo X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a0c:d450:: with SMTP id r16mr492884qvh.30.1631151506484; Wed, 08 Sep 2021 18:38:26 -0700 (PDT) Date: Thu, 9 Sep 2021 01:38:01 +0000 In-Reply-To: <20210909013818.1191270-1-rananta@google.com> Message-Id: <20210909013818.1191270-2-rananta@google.com> Mime-Version: 1.0 References: <20210909013818.1191270-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH v4 01/18] 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.153.gba50c8fa24-goog