Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp39802pxb; Tue, 12 Apr 2022 16:11:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypfIiYafu0aHohcaS5UK1kfSMqILFiZ+AfdD48QX+3la2MgkX7KG3JkNS62cyVpHhIOjjK X-Received: by 2002:a17:90a:fb97:b0:1cb:adf9:88ba with SMTP id cp23-20020a17090afb9700b001cbadf988bamr7566870pjb.46.1649805064199; Tue, 12 Apr 2022 16:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649805064; cv=none; d=google.com; s=arc-20160816; b=w5lSj4cMFK6rubcGQ1qI9qjWDgjo2gPMeprKjBYIXYQjwxiWBBy1uJBa/CYdMqO1zB UlQ047ETUIXt5LNgoF2V3Zn5jwPBlxgaYC6ZuameizlyYHksSg266GoJk4SYd1mdeDDa q+d2StVrbV9dyYL8XsfyA/tqdhPmuf6ET53/wfrhyhPXUnqi6xfXMmfAHcck6EDh6SoM gMHd4KiOhS2nEggeIFsKPLi4E5W8yS4Tj8YL9n1Ze9IOPnSD8JahWh1ujj5pnQK8GqVX hJ80sf2P4dsgGG8WPZL89QatcwJcHNuQxRdmAqBPVgL7llMmQ5nzjPHPIB5hfbIr7D4P Qg3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Y5slG8OF+UAcZaYGDxKXmAiKpk4Z0HoOivC1WQ8ffJU=; b=rid1g3m0RcKQ0NXxwN9eq884JhA28vAsxwY4FaxClScvDKoytaOcIW4l4qcjQmebBx ZQ8snHNSUfNee2xUYAI0pO57rEmJn9vqRylN7lOJQff7dHmFh7yhk0gGfdbAcEPLuxHm MkILOn0zuCvn5uvRXFkroGf66lx+lgxRxX6Se7yt0mP63ffMwYfsmjr8R3zj8MioTe/X GkyLn6BEh5O4j0/pge3D/iH1tpepufbQGrNGCPyb9M1q3zVzPk+JmmYc1z+qIr6HjPpq zYou8+Y9vviQtZ3XzFpVJgJOVzN464O3yVSPY3YV0MmxuNWbyJ/tO/9SN7kHlMGqmvw7 PoHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Iri1i1jL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 37-20020a631865000000b0039d599bc052si3771403pgy.49.2022.04.12.16.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:11:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Iri1i1jL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A2A72028B2; Tue, 12 Apr 2022 14:53:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244977AbiDLRoj (ORCPT + 99 others); Tue, 12 Apr 2022 13:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237821AbiDLRoh (ORCPT ); Tue, 12 Apr 2022 13:44:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E184E62123 for ; Tue, 12 Apr 2022 10:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649785337; 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=Y5slG8OF+UAcZaYGDxKXmAiKpk4Z0HoOivC1WQ8ffJU=; b=Iri1i1jLepZ0HBB5aAuzGYexYP+8JACYiD8R2EZJV3Yr17azW+WzDuSdAf2tOB3o4DO8TA /xwdoQmkZ5anp9h6QA47m9H5NiNDutFEN0HtvFiDVGq5VA8BK5PQldbhL+dL8TDoUsslXA dRWFwRgcwpAzbrAd05IvmA1ZdG8MQ74= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-ZiPfs4npPeGJV4Osz6HNCg-1; Tue, 12 Apr 2022 13:42:08 -0400 X-MC-Unique: ZiPfs4npPeGJV4Osz6HNCg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06F1F299E76D; Tue, 12 Apr 2022 17:42:08 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0390404D2CA; Tue, 12 Apr 2022 17:42:07 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 23CHg7ZY029784; Tue, 12 Apr 2022 13:42:07 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 23CHg6a4029780; Tue, 12 Apr 2022 13:42:06 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Tue, 12 Apr 2022 13:42:06 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Linus Torvalds cc: Alexander Viro , linux-fsdevel , Linux Kernel Mailing List , Matthew Wilcox Subject: Re: [PATCH] stat: fix inconsistency between struct stat and struct compat_stat In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 Apr 2022, Linus Torvalds wrote: > On Mon, Apr 11, 2022 at 11:41 PM Mikulas Patocka wrote: > > > > Also, if the st_dev and st_rdev values are 32-bit, we don't have to use > > old_valid_dev to test if the value fits into them. This fixes -EOVERFLOW > > on filesystems that are on NVMe because NVMe uses the major number 259. > > The problem with this part of the patch is that this: > > > @@ -353,7 +352,7 @@ static int cp_new_stat(struct kstat *sta > > #endif > > > > INIT_STRUCT_STAT_PADDING(tmp); > > - tmp.st_dev = encode_dev(stat->dev); > > + tmp.st_dev = new_encode_dev(stat->dev); > > completely changes the format of that st_dev field. we have these definitions: static __always_inline u16 old_encode_dev(dev_t dev) { return (MAJOR(dev) << 8) | MINOR(dev); } static __always_inline u32 new_encode_dev(dev_t dev) { unsigned major = MAJOR(dev); unsigned minor = MINOR(dev); return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12); } As long as both major and minor numbers are less than 256, these functions return equivalent results. So, I think it's safe to replace old_encode_dev with new_encode_dev. old_encode_dev shouldn't be called with minor >= 256, because it blends the upper minor bits into the major field - the kernel doesn't do this and checks the value with old_valid_dev before calling old_encode_dev. But when old_valid_dev returns true, it doesn't matter if you use old_encode_dev or new_encode_dev - both give equivalent results. When I tested it, both gcc and openwatcom return st_dev 0x10301, which is the expected value (the NVMe device has major 259 and minor 1). > (b) we could just hide the bits in upper bits instead. > > So what I suggest we do is to make old_encode_dev() put the minor bits > in bits 0..7 _and_ 16..23, and the major bits in 8..15 _and_ 24..32. new_encode_dev puts the minor value into bits 0..7, 20..31 and the major value into bits 8..19 So, we can use this instead of inventing a new format. Mikulas