Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2348235pxa; Mon, 3 Aug 2020 14:01:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz63P092qQRm819p9joIUJ3n0W/fguKUPYnJ7oGPxfBDdkyFYnR2OzQOwJoYlhXbR2MbrMs X-Received: by 2002:a17:907:10d9:: with SMTP id rv25mr15155812ejb.264.1596488470574; Mon, 03 Aug 2020 14:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596488470; cv=none; d=google.com; s=arc-20160816; b=jrfZVxcEYK7w/LysidqkXcMd6OcQ/fVW6UhwKP4lkHQG+QaDMt38bLIOhefwSB3M3L E5oeB/zWf5/MJjjpBwecjz1haFSWC/1z1zNpzmebKnbT2iJ5EdFkITdJ5rBeYltYVA3Y Yh16ty0hk8Xbulz0BTX3MzHsFmGM8q3FRr2GTnUwlM3RpNwsuf+gXgTS/Q3XG16YfVLK oxMMGvcU7ObqEwjUmh27x9B/dxFRk2H00qCP6AIPEmR/vnzimn5Bkyfifx8fy8KzZmZ5 3mzqFffaHBwggHYhVtF6N9DQqbVE/1RGEVFtugmTz/E9eHIf9lF5zWMf1hH8y72I/TUN nikw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=eADcXnv6Prf/ROnr8oMM90J2NN3UdejeU8L0/V+Jmmg=; b=lfMYMfA2IvIKIkRitQHleEXJX+T5xu/jLvtjIwRuS+y/br2oKy81H0osH4x/xidI3K sREbnBXtuftdYgXoc7a02n1y69ew2QxZIcCCHNpIXn2/Lb0AwavmdcuscH8Ejo/E50Rr ceSVwTaIGnBRlbEfL8iIsbT5KKiDClPZiiPbhCWK6BuWBxdenapsg93qJFxCZ7kpWoRn Q1TXqjMsAay18uOHeGVCPmIDZa2VNe0pCHwTwyxdJO2K4UXoOOYQKEuMNoR7mi5VlShK efv6KPefX8vGtmxLO4+7FMDrVwef7EGW5eevEVt6tgI0i5dU5KxjEs1K4NkX2E+Idp0G Ls/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iGOF8Y+8; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si10882640ejx.438.2020.08.03.14.00.48; Mon, 03 Aug 2020 14:01:10 -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=@redhat.com header.s=mimecast20190719 header.b=iGOF8Y+8; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729157AbgHCU75 (ORCPT + 99 others); Mon, 3 Aug 2020 16:59:57 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:26647 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729079AbgHCU75 (ORCPT ); Mon, 3 Aug 2020 16:59:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596488395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eADcXnv6Prf/ROnr8oMM90J2NN3UdejeU8L0/V+Jmmg=; b=iGOF8Y+8yuH1U4i1mXOA9BunywvSyIPMYWh4/a3/qpPNWh/OC27M/qdAzzSimxrctcp2lH rfp0Cczz7Mo1eBPfP8cFfW4jyHpjK4p+jOUqZSm8UNlL/6RY0cY8fxd2uDNRf2AXtXR65C nV7ktmHgFZ6/9KI9EibDOdsOUQq4Xdo= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-uSMih7oIOnCbwutNRQt3mg-1; Mon, 03 Aug 2020 16:58:50 -0400 X-MC-Unique: uSMih7oIOnCbwutNRQt3mg-1 Received: by mail-qt1-f200.google.com with SMTP id d2so24284111qtn.8 for ; Mon, 03 Aug 2020 13:58:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eADcXnv6Prf/ROnr8oMM90J2NN3UdejeU8L0/V+Jmmg=; b=ccfe/TxLtsFS0NNr2A6+Zi9NUurKgRMKgyM9Ub7ZmBOzJEmUvxD4nHK/MgIYs5+d23 +ALnf1vCFB3p2fYCqqjKloGBBV00JO6H6fYoeK17xxYROJ6WhqhzumBAMePpv4+tRfSX SRLVvDDwtSgmLQOxhK2h+ztMWxu7pqcbXeASxwlqz/RO5qhqBuFz6/wvaIIki7YbnMNs pzDL0cMk8tmjbinlWVqCKQsts/qr+h219YJL74zNlCzgZL/ESlcIEQ81zUuqwxolOFc8 pXs5nySxzmJUETOM6zy1CchAvV1Ot7nVKbueEnxQRDUizzPwF0NQb45c0Ou8GqXAF4A5 +87Q== X-Gm-Message-State: AOAM531wop70IHUty+RUJZ1zto8Kpo0RVnNZWsI+th4yBjS91U5E+9j3 dXLBF/hRS4HiNTNLOdPKJhBtp9XctI3KMwWrEha14pv71Id2S51V8IPSuWDgNi4vwR16hr5J4GZ hj5XHQQa3zAIJRae3olWrZx6O X-Received: by 2002:a37:a851:: with SMTP id r78mr9665289qke.419.1596488329762; Mon, 03 Aug 2020 13:58:49 -0700 (PDT) X-Received: by 2002:a37:a851:: with SMTP id r78mr9665273qke.419.1596488329535; Mon, 03 Aug 2020 13:58:49 -0700 (PDT) Received: from redhat.com (bzq-79-177-102-128.red.bezeqint.net. [79.177.102.128]) by smtp.gmail.com with ESMTPSA id e4sm23451075qts.57.2020.08.03.13.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 13:58:49 -0700 (PDT) Date: Mon, 3 Aug 2020 16:58:46 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, Jason Wang Subject: [PATCH v2 03/24] virtio: allow __virtioXX, __leXX in config space Message-ID: <20200803205814.540410-4-mst@redhat.com> References: <20200803205814.540410-1-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200803205814.540410-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently all config space fields are of the type __uXX. This confuses people and some drivers (notably vdpa) access them using CPU endian-ness - which only works well for legacy or LE platforms. Update virtio_cread/virtio_cwrite macros to allow __virtioXX and __leXX field types. Follow-up patches will convert config space to use these types. Signed-off-by: Michael S. Tsirkin --- include/linux/virtio_config.h | 50 +++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 3b4eae5ac5e3..64da491936f7 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -6,6 +6,7 @@ #include #include #include +#include #include struct irq_affinity; @@ -287,12 +288,57 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) return __cpu_to_virtio64(virtio_is_little_endian(vdev), val); } +/* + * Only the checker differentiates between __virtioXX and __uXX types. But we + * try to share as much code as we can with the regular GCC build. + */ +#if !defined(CONFIG_CC_IS_GCC) && !defined(__CHECKER__) + +/* Not a checker - we can keep things simple */ +#define __virtio_native_typeof(x) typeof(x) + +#else + +/* + * We build this out of a couple of helper macros in a vain attempt to + * help you keep your lunch down while reading it. + */ +#define __virtio_pick_value(x, type, then, otherwise) \ + __builtin_choose_expr(__same_type(x, type), then, otherwise) + +#define __virtio_pick_type(x, type, then, otherwise) \ + __virtio_pick_value(x, type, (then)0, otherwise) + +#define __virtio_pick_endian(x, x16, x32, x64, otherwise) \ + __virtio_pick_type(x, x16, __u16, \ + __virtio_pick_type(x, x32, __u32, \ + __virtio_pick_type(x, x64, __u64, \ + otherwise))) + +#define __virtio_native_typeof(x) typeof( \ + __virtio_pick_type(x, __u8, __u8, \ + __virtio_pick_endian(x, __virtio16, __virtio32, __virtio64, \ + __virtio_pick_endian(x, __le16, __le32, __le64, \ + __virtio_pick_endian(x, __u16, __u32, __u64, \ + /* No other type allowed */ \ + (void)0))))) + +#endif + +#define __virtio_native_type(structname, member) \ + __virtio_native_typeof(((structname*)0)->member) + +#define __virtio_typecheck(structname, member, val) \ + /* Must match the member's type, and be integer */ \ + typecheck(__virtio_native_type(structname, member), (val)) + + /* Config space accessors. */ #define virtio_cread(vdev, structname, member, ptr) \ do { \ might_sleep(); \ /* Must match the member's type, and be integer */ \ - if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \ + if (!__virtio_typecheck(structname, member, *(ptr))) \ (*ptr) = 1; \ \ switch (sizeof(*ptr)) { \ @@ -322,7 +368,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) do { \ might_sleep(); \ /* Must match the member's type, and be integer */ \ - if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \ + if (!__virtio_typecheck(structname, member, *(ptr))) \ BUG_ON((*ptr) == 1); \ \ switch (sizeof(*ptr)) { \ -- MST