From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by sourceware.org (Postfix) with ESMTPS id 693E03858425 for ; Tue, 5 Sep 2023 17:28:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 693E03858425 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1ccb6a69b13so2284575fac.2 for ; Tue, 05 Sep 2023 10:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693934905; x=1694539705; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ASsI/WQaSSxUUTcVNi988UJONjk3a3Yw84wYxOi3EhY=; b=mseZtV5qBkgs66eFEB9CePDOxyF0Shm/l4YyKDlWbhmNrtqy6RM38kmwHoG7wzB/Pg yo2BSJBg1gA7qexuQgFWZUsiKViS0dvPyy1Ai+Vq7SdxurpJfwzDePdaESfFW46vdiYD eDeWU9EGrwxAuJS0BKBzrBuwmZqPgKnbGzZfINb/uh+vLZIfNgeFJvVBylba8dXpKuFV Q6AT4e9zrWoDrredQ75m2wxE/EkJFpYzjOHuFpQSYxQb7ToqhcpEcYPJi/m9WU1sEiVS khmC0+NpuOxnItDAP1gjorMKmyeukPe7B/3WMngCwzu0llAt/Zua0Qw6qw4rCQh/SlPv UWwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693934905; x=1694539705; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ASsI/WQaSSxUUTcVNi988UJONjk3a3Yw84wYxOi3EhY=; b=E6wFq90wiIzRheL57chieQTnqu8GdEktQ29+ZFaixaaSBVOfq0ZMsvuhH3qeDUCyGl zBO+cvEqfCv1tgn5cPbe/zz4+sfY1Zy3TfugQYKGrZ8iRm32GeX1Fu6Om9tgA/q1P7S2 zpuwx2nROYt2xx6bJeYkBxQ9uAaXwUSF5kR0aHAGcrLqcfvoHt1ftmL/JlVjVc3bEYrF uisC0DKrN0W7QtuFtQgfSbZaXynYRKayFPk4c24uOw1wFXVi37rBbjlRSfUJSSSnH+1b RCVyif6OUI66nU48tGgsLybkP6rysAi42uD9AyODQq7oKj0ZGKJc6+m71P0YHig7ktJM ESBA== X-Gm-Message-State: AOJu0YxiRZsuzsZhZLfRmxkauTzU4Nc59JBXr8P4Fynrl7D+X56o16k5 DFNFy25j5ZyjSuLXhunCbqgHyJFRXVw+Rqf2pQAbUg== X-Google-Smtp-Source: AGHT+IEaT/ZTlsxI7hi2//WkAxsmDKGcNVSQeyN1xTFH8rwpP2dvda2PRMw66rYM+QQyf68nx3f9nQ== X-Received: by 2002:a05:6870:a70d:b0:1bb:4d4e:ea69 with SMTP id g13-20020a056870a70d00b001bb4d4eea69mr16238456oam.54.1693934905691; Tue, 05 Sep 2023 10:28:25 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c3:fee4:2809:dda4:f5fb:fd76? ([2804:1b3:a7c3:fee4:2809:dda4:f5fb:fd76]) by smtp.gmail.com with ESMTPSA id j12-20020a056870168c00b001d4c5e4c2c5sm3168234oae.25.2023.09.05.10.28.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Sep 2023 10:28:25 -0700 (PDT) Message-ID: <6d0e4e9e-ab69-0c73-bb9d-ce344b4a043b@linaro.org> Date: Tue, 5 Sep 2023 14:28:22 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: fstat(2) penalized by using newfstatat(6, "", buf, AT_EMPTY_PATH) Content-Language: en-US To: Mateusz Guzik Cc: Andreas Schwab , Rich Felker , Mateusz Guzik via Libc-alpha , Linus Torvalds References: <680b330d-6ef3-adc5-9ba6-cf74dd53e422@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 05/09/23 10:14, Mateusz Guzik wrote: > On 9/5/23, Adhemerval Zanella Netto wrote: >> If I understand correctly, the issue seems to be the usage of a empty string >> >> sentinel ("") to indicate the argument it not really used (which trigger >> all >> the SMAP issues since kernel will always try to copy the argument from >> userland). This also means on x86_64 you will also have this performance >> penalty on syscalls that use AT_EMPTY_PATH (i.e, execveat, >> name_to_handle_at, >> open_tree, faccessat, etc.). I really think it would better fixed in the >> kernel instead of adding extra constraints for the userland. >> > > I completely agree this is a problem going way past fstat. > > One could be tempted to allow NULL with the flag, but that wont work > -- I know of code out there which checks for statx availability by > deliberately passing a NULL path. I would not be shocked if there was > more of the sort and passing the AT_EMPTY_PATH flag on top. I though about it, but besides being a clear kABI breakage it does not help on older kernels (where fstat returns EFAULT for NULL). I am not sure about how this statx availability would work, passing NULL would returns EFAULT in both statx and old stat cases. > > I am considering proposing a new flag which combined with NULL path > would indicate there is only a fd lookup to perform -- fuly backwards > compatible and avoiding the problem. Then syscalls could start > supporting it over time as people get around to it> > However, the fstab stub in glibc does not have to suffer it regardless > of what happens with the above. I think we can still make it in a generic way, stat family would use more syscall (which some filters might complain) but it should be ok: diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c index 3509d3ca6d..9fc7f82db2 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -91,20 +91,30 @@ fstatat64_time64_stat (int fd, const char *file, struct __stat64_t64 *buf, int flag) { int r; + bool is_fstat = flag == AT_EMPTY_PATH && fd >= 0 && file[0] == '\0'; #if XSTAT_IS_XSTAT64 # ifdef __NR_newfstatat /* 64-bit kABI, e.g. aarch64, ia64, powerpc64*, s390x, riscv64, and x86_64. */ - r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, buf, flag); + if (is_fstat) + r = INTERNAL_SYSCALL_CALL (fstat, fd, buf); + else + r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, buf, flag); # elif defined __NR_fstatat64 # if STAT64_IS_KERNEL_STAT64 /* 64-bit kABI outlier, e.g. alpha */ - r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, buf, flag); + if (is_fstat) + r = INTERNAL_SYSCALL_CALL (fstat64, fd, buf); + else + r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, buf, flag); # else /* 64-bit kABI outlier, e.g. sparc64. */ struct kernel_stat64 kst64; - r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &kst64, flag); + if (is_fstat) + r = INTERNAL_SYSCALL_CALL (fstat64, fd, &kst64); + else + r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &kst64, flag); if (r == 0) __cp_stat64_kstat64 (buf, &kst64); # endif @@ -115,7 +125,10 @@ fstatat64_time64_stat (int fd, const char *file, struct __stat64_t64 *buf, e.g. arm, csky, i386, hppa, m68k, microblaze, nios2, sh, powerpc32, and sparc32. */ struct stat64 st64; - r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); + if (is_fstat) + r = INTERNAL_SYSCALL_CALL (fstat64, fd, &st64); + else + r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); if (r == 0) { /* Clear both pad and reserved fields. */ @@ -138,7 +151,10 @@ fstatat64_time64_stat (int fd, const char *file, struct __stat64_t64 *buf, # else /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */ struct kernel_stat kst; - r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag); + if (is_fstat) + r = INTERNAL_SYSCALL_CALL (fstat, fd, &kst); + else + r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag); if (r == 0) __cp_kstat_stat64_t64 (&kst, buf); # endif