Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2627240yba; Mon, 8 Apr 2019 00:50:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3ZIcTsZTfQ+M7eOUL1Bgh8XXhCM9TdRU8QDOlgcrqoo1YrOQQnDspLNBWde6Mt1KhFCMY X-Received: by 2002:a62:f24e:: with SMTP id y14mr27667473pfl.209.1554709830566; Mon, 08 Apr 2019 00:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554709830; cv=none; d=google.com; s=arc-20160816; b=LcxM9DnPPgr+fattle5JyElynYZy66W9m4LrMT3MgmxZYIPLjQFx57rUB/M8Qg3pt0 hIBHTbo7yfs1eZ6VlJR4ORQbIlnYnqu35IYydpyXzjgZQY4tezoGD9iJK58V4hYMgGxp DeVnKU+FWW35AP1Uuf8zrsjsbFd9gfabYf6pCvr0XIeEhwwauzIwgQR49PzpKvUY3bTE jRGK07dzhmBRL9BlrgZN8xFmmhygrOl+JJyupr4cb4Z9xJTvuqLt0KbRO3sku41jKsGJ PIKEXgsUtOkdboXCozaWTe1TwXpC1j395Fm+4TW9UgyNqXESZ44JS9R2WG5K1N2gowrd QqZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=al1vgi3fUgikN3Vb7zvv11FgEA/D21/dKxK7qChqvOc=; b=tz+B1pocZ0aM2pCFCmDsJE0anlKnBdk+rCRHXE/2pLCePH79bpIKuNdfF5eFDQLM4X oDT6rKjq/ShPIVIxhEZ1qoWzlqUmGjYwT38dhALi7/wbxaVOudMAyKuX5D0xG6vGs0KD HDcy7VcOkFaFUtYL69ehCt2g8KGTtk8NDvf4fTahcQa71TNkjQwyNnjkokroZ6eCdqMG 7hm0K4oT5ueTyjnqNuTNs5xt2ouFb7UqNuUPeb40IjczXSAZNy3eDcofgJmbpyt2UFIk efH1xiKNXyQem/Qh1/cnkSygYtgmwOJGbl46camR2ZucSK5bVWHLdqWjOTlGKb6Dj2e2 5tXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z70si25776760pgd.86.2019.04.08.00.50.14; Mon, 08 Apr 2019 00:50:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726369AbfDHHtj (ORCPT + 99 others); Mon, 8 Apr 2019 03:49:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36862 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbfDHHtj (ORCPT ); Mon, 8 Apr 2019 03:49:39 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 70B5381233; Mon, 8 Apr 2019 07:49:39 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F24DB6013C; Mon, 8 Apr 2019 07:49:37 +0000 (UTC) From: Florian Weimer To: Alexey Dobriyan Cc: Peter Zijlstra , mingo@redhat.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCH] sched/core: expand sched_getaffinity(2) to return number of CPUs References: <20190403200809.GA13876@avx2> <20190404084249.GS4038@hirez.programming.kicks-ass.net> <87wok83gfs.fsf@oldenburg2.str.redhat.com> <20190406194825.GA5106@avx2> Date: Mon, 08 Apr 2019 09:49:35 +0200 In-Reply-To: <20190406194825.GA5106@avx2> (Alexey Dobriyan's message of "Sat, 6 Apr 2019 22:48:25 +0300") Message-ID: <878swlszqo.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 08 Apr 2019 07:49:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Alexey Dobriyan: >> >> Patch overloads sched_getaffinity(len=0) to simply return "nr_cpu_ids". >> >> This will make gettting CPU mask require at most 2 system calls >> >> and will eliminate unnecessary code. >> >> >> >> len=0 is chosen so that >> >> * passing zeroes is the simplest thing >> >> >> >> syscall(__NR_sched_getaffinity, 0, 0, NULL) >> >> >> >> will simply do the right thing, >> >> >> >> * old kernels returned -EINVAL unconditionally. >> >> >> >> Note: glibc segfaults upon exiting from system call because it tries to >> >> clear the rest of the buffer if return value is positive, so >> >> applications will have to use syscall(3). >> >> Good news is that it proves noone uses sched_getaffinity(pid, 0, NULL). >> >> Given that old kernels fail with EINVAL, that evidence is fairly >> restricted. >> >> I'm not sure if it's a good idea to overload this interface. I expect >> that users will want to call sched_getaffinity (the system call wrapper) >> with cpusetsize == 0 to query the value, so there will be pressure on >> glibc to remove the memset. At that point we have an API that obscurely >> fails with old glibc versions, but suceeds with newer ones, which isn't >> great. > > I can do "if (len == 536870912)" so that bit count overflows on old > kernels into EINVAL and is unlikely to be used ever. I don't see how this solves this particular issue. It will still result in a mysterious crash if programs use an updated system call wrapper. Thanks, Florian