Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4532929imm; Wed, 30 May 2018 07:22:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKHgiTz/w9EsJTNsyv1aeIBLE/AGnumachNftv5FuXcJmdVNWGEMuyDDtcm1xANR9uFcVbO X-Received: by 2002:a17:902:1c7:: with SMTP id b65-v6mr3043523plb.298.1527690141041; Wed, 30 May 2018 07:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527690141; cv=none; d=google.com; s=arc-20160816; b=nFSffCDmeO5I66Yh9I0I67/5Z6nXrRsSCd6CepCofIB5mtxUbmhtnte5N15O4+deN8 qnFgpfAd3xiyU3Hy9ccDuGaO4BTESg2EprvsSiPmJkYA5YWbdgYpDvsM3/g4PbpKRgkG /k1vWnl9+Xcoyq3qsrUx/Y43K3zJ3zzW+kQUZNS0LeSQLNVbwJAiTnQCd02j6AwG1PPA Cf2thtHncuthrTZWsUcCKmr8ZUZEeneCRpfj94w6tESZmBoWPQhDvjfcnL8qq52TUInK UraU/wc9dsxrVM/ARcxla5kDP8g231oNil7tNnt/Z7aw7ScMR0MWEDA5ctUiKSyY/sxe +mpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:to :from:arc-authentication-results; bh=szuvoC90G6I67uXFJZSG+mgswYXVqyNfqH5pbbELMe4=; b=nlulXyTdULlF1wdZ302jUrr/4EKzu4/H27Y9DcNcB5aPyd8ek1fhZDDv3OR7QZxuIB ZNVyqHXE2hG0KInniQVJFXIW2CsS/C/bn98dWYEnzHoCqbrummW+a5PQe206FZv7zSPG CBm0caw86WbbGHxl5q/IIMzO/CNbcDk3mq5/OO+UT33SUkGvP2Ohm+Bfad34Mndvy2dR jKxuH0AOhTneoq4dTYWJErvhgAjfx0z71FHvMGKzzvXgiWwa1D/VFxY7e07eZJFx6iOn nCqw02xcNTauZ17Xrf94jiXKnGqsOJ1p5dA+DXeylK+o3FhPSSxD/YjL9TFacUSwpWyL LdbA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15-v6si11549337pga.252.2018.05.30.07.22.06; Wed, 30 May 2018 07:22:21 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752872AbeE3OV3 (ORCPT + 99 others); Wed, 30 May 2018 10:21:29 -0400 Received: from seldsegrel01.sonyericsson.com ([37.139.156.29]:11360 "EHLO SELDSEGREL01.sonyericsson.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751630AbeE3OV0 (ORCPT ); Wed, 30 May 2018 10:21:26 -0400 X-Greylist: delayed 602 seconds by postgrey-1.27 at vger.kernel.org; Wed, 30 May 2018 10:21:26 EDT From: Peter Enderborg To: , Paul Moore , Stephen Smalley , Eric Paris , James Morris , Daniel Jurgens , Doug Ledford , , , , "Serge E . Hallyn" , "Paul E . McKenney" Subject: [PATCH V3 0/5] selinux:Significant reduce of preempt_disable holds Date: Wed, 30 May 2018 16:10:59 +0200 Message-ID: <20180530141104.28569-1-peter.enderborg@sony.com> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Holding the preempt_disable is very bad for low latency tasks such as audio and therefore we need to break out the rule-set dependent part from this disable. By using a RCU instead of rwlock we have an efficient locking and less preemption interference. Selinux uses a lot of read_locks. This patch replaces the rwlock with RCU that does not hold preempt_disable. Intel Xeon W3520 2.67 Ghz running FC27 with 4.15.0-rc9git (+measurement) I get preempt_disable of about 1.2ms in security_compute_av(). With the patch I get 960us as the longest security_compute_av() without preempt disabeld. There are very much noise in the measurement but it is not likely a degrade. And the preempt_disable times is also very dependent on the selinux rule-set. In security_get_user_sids() we have two nested for-loops and the inner part calls sittab_context_to_sid() that calls sidtab_search_context() that has a for loop() over a while() where the loops is dependent on the rules. On the test system the average lookup time is 60us and does not change with the introduced RCU usage. The boolean change becomes a lot more heavy with this patch, but it is a very rare usage in compare with read only operations. The lock held during a policydb_copy is about 1ms on a XEON. To use RCU the structure of policydb has to be accesses through a pointer. We need 5 patches to get there. [PATCH V3 1/5 selinux-next] selinux: Make allocation atomic in policydb objects functions. This patch change the allocation for policydb objects. They are in its own patch to make the complicated part easier to read. [PATCH V3 2/5 selinux-next] selinux: Introduce selinux_ruleset struct This makes the access for the rule evaluation going though a single pointer. [PATCH V3 3/5 selinux-next] selinux: sidtab_clone switch to use rwlock. We need to make sidtabs copys so this patch change the locks to a rwlock and create a copy function. [PATCH V3 4/5 selinux-next] selinux: seqno separation This patch adds separation of the read and write and uses the pointer to switch rule set. It uses seqno for error handling since there are a possibility to have multiple access. [PATCH V3 5/5 selinux-next] selinux: Switch to rcu read locks for avc_compute All the preparation is done so this patch do the change of locks to rcu. History: V1 rwsem V2 did not handle all policydb objects, solved with the policydb_copy did not handle sidtab for booleans, I think this one does however shutdown is not used but not removed.