Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1910476pxa; Thu, 6 Aug 2020 20:30:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5xlhRYoBdTnSaCca4eQ0GAZtawqsxwxEYOXaKDJYlAXjb2BRoHsVo6HkzeLQDGXjb+JLL X-Received: by 2002:a17:906:95cb:: with SMTP id n11mr7192066ejy.506.1596771014121; Thu, 06 Aug 2020 20:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596771014; cv=none; d=google.com; s=arc-20160816; b=JtzK80pFeZnSaaWGt7isnSmTKCZTwlPErf7l0x4xB6b3JuqAF3ztQoCU2WSE1k6wP3 O7KCFfu3DdcFwPhsz3lreOJ+/3O02t0E6Zuy9ZqClhV4pgH/bV1Hadw8nJXnGFetyix9 zZm+ANmSzWdfwWDhxtEKwymRWTv0cnkQoY7N8Aq5yjvWTtuwvI8gySJqdtF3gpo4S+Oy s3kXdCWYHNFJw69c3HipHLJX7gv5yezZ5KcWDx5G0GDJ69Tq0sdY2ubk/8WFQDf5e6bR 2n7WxmkwsAAi/ZE7ezXxv98lvgOsGborCjx8qWdmDJQ/s7B+rTW/60Y3V5lG25te0gY1 hbYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=PzBVMxtG2p8vYea4PsugHNCB46PX04hMXUf43TE1qM8=; b=JjPErocSV2+ZpilxZ23/SbEhbCmxR+HDCKv8RYFizfLuPQjw1bOfuHEAmQ4kd9qF5+ Yyf/euCVwrI8hbBPfX7Kv8Y3jhrFomzLkWisMvT5sXNPStcB/BsY9cWjIdeKYQuOkVL6 hHGuv2xXNwEXu8W1/p2dh+MmV/1iROB8osbUJnwrI2j+TNVczXJEGtYzenEMJdlqzWuM eaqvdeSopOyZIim2G+aDcTx6SRyKyUUNQ5z5FVEwob/SagFwqnci3YpPI8zLAsP+zZMP +HB5uCANbPV4PaptZ5YNu7Ufed8XQKfAQ0l/yWdBO0jD5fwJhoc8rswIeFwj2UkiZwa0 OGKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VkZWRvcE; 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 v23si4287673edw.343.2020.08.06.20.29.51; Thu, 06 Aug 2020 20:30:14 -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=VkZWRvcE; 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 S1726104AbgHGD1G (ORCPT + 99 others); Thu, 6 Aug 2020 23:27:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20340 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726055AbgHGD1G (ORCPT ); Thu, 6 Aug 2020 23:27:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596770825; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PzBVMxtG2p8vYea4PsugHNCB46PX04hMXUf43TE1qM8=; b=VkZWRvcEfrNplcAoweCEX+niiIFh67ohVytaIyurCz+miFQCxlhQK9Xf14+GrRIt9O2O2m B4v+Z936UJhbwed6wEVLBcqllxBXOWuqggph541tQzqMwy7QudMT7LQvqjWNTnsfVH91jM L5LhuD4igpvvlobaA5q1og/qgcBPGoU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-221-Bc6xhlj6Opam2uxRH5xr5Q-1; Thu, 06 Aug 2020 23:27:02 -0400 X-MC-Unique: Bc6xhlj6Opam2uxRH5xr5Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC21518C63E7; Fri, 7 Aug 2020 03:27:01 +0000 (UTC) Received: from [10.72.13.215] (ovpn-13-215.pek2.redhat.com [10.72.13.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id D31B587A66; Fri, 7 Aug 2020 03:26:57 +0000 (UTC) Subject: Re: [PATCH v2 03/24] virtio: allow __virtioXX, __leXX in config space To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org References: <20200803205814.540410-1-mst@redhat.com> <20200803205814.540410-4-mst@redhat.com> <20200805074434-mutt-send-email-mst@kernel.org> <4aa65ad6-5324-0a8c-0fa6-0d8e680f0706@redhat.com> <20200806015604-mutt-send-email-mst@kernel.org> From: Jason Wang Message-ID: Date: Fri, 7 Aug 2020 11:26:55 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200806015604-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/6 下午1:58, Michael S. Tsirkin wrote: > On Thu, Aug 06, 2020 at 11:37:38AM +0800, Jason Wang wrote: >> On 2020/8/5 下午7:45, Michael S. Tsirkin wrote: >>>>> #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; \ >>>> A silly question,  compare to using set()/get() directly, what's the value >>>> of the accessors macro here? >>>> >>>> Thanks >>> get/set don't convert to the native endian, I guess that's why >>> drivers use cread/cwrite. It is also nice that there's type >>> safety, checking the correct integer width is used. >> >> Yes, but this is simply because a macro is used here, how about just doing >> things similar like virtio_cread_bytes(): >> >> static inline void virtio_cread(struct virtio_device *vdev, >>                       unsigned int offset, >>                       void *buf, size_t len) >> >> >> And do the endian conversion inside? >> >> Thanks >> > Then you lose type safety. It's very easy to have an le32 field > and try to read it into a u16 by mistake. > > These macros are all about preventing bugs: and the whole patchset > is about several bugs sparse found - that is what prompted me to make > type checks more strict. Yes, but we need to do the macro with compiler extensions. I wonder whether or not the kernel has already had something since this request here is pretty common? Thanks > >